python-telegram-bot/telegram/userprofilephotos.py

37 lines
1,009 B
Python
Raw Normal View History

2015-07-08 15:10:08 +02:00
#!/usr/bin/env python
2015-07-09 16:40:44 +02:00
import json
2015-07-17 16:53:54 +02:00
from .telegram_boject_base import Base
2015-07-09 16:40:44 +02:00
2015-07-17 16:53:54 +02:00
class UserProfilePhotos(Base):
2015-07-09 02:58:13 +02:00
def __init__(self,
total_count,
photos):
self.total_count = total_count
self.photos = photos
2015-07-08 15:10:08 +02:00
@staticmethod
def de_json(data):
2015-07-08 15:10:08 +02:00
if 'photos' in data:
from telegram import PhotoSize
photos = []
for photo in data['photos']:
photos.append([PhotoSize.de_json(x) for x in photo])
2015-07-08 15:10:08 +02:00
else:
photos = None
2015-07-08 15:10:08 +02:00
return UserProfilePhotos(total_count=data.get('total_count', None),
photos=photos)
2015-07-09 16:40:44 +02:00
def to_json(self):
json_data = {}
if self.total_count:
json_data['total_count'] = self.total_count
if self.photos:
json_data['photos'] = []
for photo in self.photos:
json_data['photos'].append([x.to_json() for x in photo])
2015-07-20 03:06:07 +02:00
return json.dumps(json_data)