mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-03 09:49:21 +01:00
Adding getUserProfilePhotos
This commit is contained in:
parent
c20d6465fc
commit
0b19099eea
4 changed files with 51 additions and 4 deletions
|
@ -20,7 +20,7 @@ from video import Video
|
|||
from location import Location
|
||||
from chataction import ChatAction
|
||||
# from inputfile import InputFile
|
||||
# from userprofilephotos import UserProfilePhotos
|
||||
from userprofilephotos import UserProfilePhotos
|
||||
# from replykeyboardmarkup import ReplyKeyboardMarkup
|
||||
# from replykeyboardhide import ReplyKeyboardHide
|
||||
# from forcereply import ForceReply
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
"""A library that provides a Python interface to the Telegram Bots API"""
|
||||
"""A library that provides a Python interface to the Telegram Bot API"""
|
||||
|
||||
import json
|
||||
import requests
|
||||
|
||||
from telegram import (User, Message, Update)
|
||||
from telegram import (User, Message, Update, UserProfilePhotos)
|
||||
|
||||
|
||||
class Bot(object):
|
||||
|
@ -385,9 +385,25 @@ class Bot(object):
|
|||
|
||||
self._requestUrl(url, 'POST', data=data)
|
||||
|
||||
def getUserProfilePhotos(self):
|
||||
def getUserProfilePhotos(self,
|
||||
user_id,
|
||||
offset=None,
|
||||
limit=100):
|
||||
|
||||
url = '%s/getUserProfilePhotos' % (self.base_url)
|
||||
|
||||
data = {'user_id': user_id}
|
||||
|
||||
if offset:
|
||||
data['offset'] = offset
|
||||
if limit:
|
||||
data['limit'] = limit
|
||||
|
||||
json_data = self._requestUrl(url, 'POST', data=data)
|
||||
data = self._parseAndCheckTelegram(json_data.content)
|
||||
|
||||
return UserProfilePhotos.newFromJsonDict(data)
|
||||
|
||||
def getUpdates(self,
|
||||
offset=None,
|
||||
limit=100,
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
class UserProfilePhotos(object):
|
||||
def __init__(self, **kwargs):
|
||||
param_defaults = {
|
||||
'total_count': None,
|
||||
'photos': None
|
||||
}
|
||||
|
||||
for (param, default) in param_defaults.iteritems():
|
||||
setattr(self, param, kwargs.get(param, default))
|
||||
|
||||
@staticmethod
|
||||
def newFromJsonDict(data):
|
||||
if 'photos' in data:
|
||||
from telegram import PhotoSize
|
||||
photos = []
|
||||
for photo in data['photos']:
|
||||
photos.append([PhotoSize.newFromJsonDict(x) for x in photo])
|
||||
else:
|
||||
photos= None
|
||||
|
||||
return UserProfilePhotos(total_count=data.get('total_count', None),
|
||||
photos=photos)
|
|
@ -115,3 +115,9 @@ class BotTest(unittest.TestCase):
|
|||
message = self._bot.sendChatAction(action=telegram.ChatAction.TYPING,
|
||||
chat_id=12173560)
|
||||
# TODO: return json
|
||||
|
||||
def testGetUserProfilePhotos(self):
|
||||
'''Test the telegram.Bot getUserProfilePhotos method'''
|
||||
print 'Testing getUserProfilePhotos'
|
||||
upf = self._bot.getUserProfilePhotos(user_id=12173560)
|
||||
self.assertEqual(8314, upf.photos[0][0].file_size)
|
||||
|
|
Loading…
Reference in a new issue