diff --git a/CHANGES b/CHANGES index 9db150260..216596dfb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,16 @@ +2015-07-20 + Released 2.1 + Fix to_dict for Document and Video + + +2015-07-19 + + Released 2.0 + Fixes bugs + Improves __str__ over to_json() + Creates abstractclass TelegramObject + + 2015-07-15 Released 1.9 diff --git a/setup.py b/setup.py index 7782641e2..5d6f7c54a 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def read(*paths): setup( name='python-telegram-bot', - version='1.9', + version='2.1', author='Leandro Toledo', author_email='leandrotoledodesouza@gmail.com', license='GPLv2', diff --git a/telegram/__init__.py b/telegram/__init__.py index dac66684c..70b2ea7e3 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -3,7 +3,7 @@ """A library that provides a Python interface to the Telegram Bots API""" __author__ = 'leandrotoledodesouza@gmail.com' -__version__ = '1.9' +__version__ = '2.1' from .base import TelegramObject from .user import User diff --git a/telegram/audio.py b/telegram/audio.py index db2705cb5..98550724d 100644 --- a/telegram/audio.py +++ b/telegram/audio.py @@ -22,7 +22,7 @@ class Audio(TelegramObject): mime_type=data.get('mime_type', None), file_size=data.get('file_size', None)) - def to_data(self): + def to_dict(self): data = {'file_id': self.file_id, 'duration': self.duration} if self.mime_type: diff --git a/telegram/base.py b/telegram/base.py index 491a5e717..c8bfb6121 100644 --- a/telegram/base.py +++ b/telegram/base.py @@ -11,7 +11,7 @@ class TelegramObject(object): __metaclass__ = ABCMeta def __str__(self): - return str(self.to_data()) + return str(self.to_dict()) def __getitem__(self, item): return self.__dict__[item] @@ -21,8 +21,8 @@ class TelegramObject(object): raise NotImplementedError def to_json(self): - return json.dumps(self.to_data()) + return json.dumps(self.to_dict()) @abstractmethod - def to_data(self): + def to_dict(self): return diff --git a/telegram/contact.py b/telegram/contact.py index c8a365da0..a34436774 100644 --- a/telegram/contact.py +++ b/telegram/contact.py @@ -22,7 +22,7 @@ class Contact(TelegramObject): last_name=data.get('last_name', None), user_id=data.get('user_id', None)) - def to_data(self): + def to_dict(self): data = {'phone_number': self.phone_number, 'first_name': self.first_name} if self.last_name: diff --git a/telegram/document.py b/telegram/document.py index 9077a7152..b0e6326cd 100644 --- a/telegram/document.py +++ b/telegram/document.py @@ -31,9 +31,10 @@ class Document(TelegramObject): mime_type=data.get('mime_type', None), file_size=data.get('file_size', None)) - def to_data(self): - data = {'file_id': self.file_id, - 'thumb': self.thumb.to_data()} + def to_dict(self): + data = {'file_id': self.file_id} + if self.thumb: + data['thumb'] = self.thumb.to_dict() if self.file_name: data['file_name'] = self.file_name if self.mime_type: diff --git a/telegram/forcereply.py b/telegram/forcereply.py index 3501bea48..08e35e781 100644 --- a/telegram/forcereply.py +++ b/telegram/forcereply.py @@ -16,7 +16,7 @@ class ForceReply(TelegramObject): return ForceReply(force_reply=data.get('force_reply', None), selective=data.get('selective', None)) - def to_data(self): + def to_dict(self): data = {'force_reply': self.force_reply} if self.selective: data['selective'] = self.selective diff --git a/telegram/groupchat.py b/telegram/groupchat.py index 340854a90..a7725f7e7 100644 --- a/telegram/groupchat.py +++ b/telegram/groupchat.py @@ -16,7 +16,7 @@ class GroupChat(TelegramObject): return GroupChat(id=data.get('id', None), title=data.get('title', None)) - def to_data(self): + def to_dict(self): data = {'id': self.id, 'title': self.title} return data diff --git a/telegram/location.py b/telegram/location.py index 73a3f99eb..1387bbb0a 100644 --- a/telegram/location.py +++ b/telegram/location.py @@ -16,7 +16,7 @@ class Location(TelegramObject): return Location(longitude=data.get('longitude', None), latitude=data.get('latitude', None)) - def to_data(self): + def to_dict(self): data = {'longitude': self.longitude, 'latitude': self.latitude} return data diff --git a/telegram/message.py b/telegram/message.py index d0ea9b196..4e139e060 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -163,11 +163,11 @@ class Message(TelegramObject): delete_chat_photo=data.get('delete_chat_photo', None), group_chat_created=data.get('group_chat_created', None)) - def to_data(self): + def to_dict(self): data = {'message_id': self.message_id, - 'from': self.from_user.to_data(), + 'from': self.from_user.to_dict(), 'date': self.date, - 'chat': self.chat.to_data()} + 'chat': self.chat.to_dict()} if self.forward_from: data['forward_from'] = self.forward_from if self.forward_date: @@ -177,19 +177,19 @@ class Message(TelegramObject): if self.text: data['text'] = self.text if self.audio: - data['audio'] = self.audio.to_data() + data['audio'] = self.audio.to_dict() if self.document: - data['document'] = self.document.to_data() + data['document'] = self.document.to_dict() if self.photo: - data['photo'] = [p.to_data() for p in self.photo] + data['photo'] = [p.to_dict() for p in self.photo] if self.sticker: - data['sticker'] = self.sticker.to_data() + data['sticker'] = self.sticker.to_dict() if self.video: - data['video'] = self.video.to_data() + data['video'] = self.video.to_dict() if self.contact: - data['contact'] = self.contact.to_data() + data['contact'] = self.contact.to_dict() if self.location: - data['location'] = self.location.to_data() + data['location'] = self.location.to_dict() if self.new_chat_participant: data['new_chat_participant'] = self.new_chat_participant if self.left_chat_participant: diff --git a/telegram/photosize.py b/telegram/photosize.py index c0a458a15..31b4ab09c 100644 --- a/telegram/photosize.py +++ b/telegram/photosize.py @@ -22,7 +22,7 @@ class PhotoSize(TelegramObject): height=data.get('height', None), file_size=data.get('file_size', None)) - def to_data(self): + def to_dict(self): data = {'file_id': self.file_id, 'width': self.width, 'height': self.height} diff --git a/telegram/replykeyboardhide.py b/telegram/replykeyboardhide.py index 53d8c58b9..c59155d2f 100644 --- a/telegram/replykeyboardhide.py +++ b/telegram/replykeyboardhide.py @@ -16,7 +16,7 @@ class ReplyKeyboardHide(ReplyMarkup): return ReplyKeyboardHide(hide_keyboard=data.get('hide_keyboard', None), selective=data.get('selective', None)) - def to_data(self): + def to_dict(self): data = {'hide_keyboard': self.hide_keyboard} if self.selective: data['selective'] = self.selective diff --git a/telegram/replykeyboardmarkup.py b/telegram/replykeyboardmarkup.py index df52e2407..a3bd7ea78 100644 --- a/telegram/replykeyboardmarkup.py +++ b/telegram/replykeyboardmarkup.py @@ -26,7 +26,7 @@ class ReplyKeyboardMarkup(ReplyMarkup): ), selective=data.get('selective', None)) - def to_data(self): + def to_dict(self): data = {'keyboard': self.keyboard} if self.resize_keyboard: data['resize_keyboard'] = self.resize_keyboard diff --git a/telegram/sticker.py b/telegram/sticker.py index fa02b322f..6465ea4c8 100644 --- a/telegram/sticker.py +++ b/telegram/sticker.py @@ -31,11 +31,11 @@ class Sticker(TelegramObject): thumb=thumb, file_size=data.get('file_size', None)) - def to_data(self): + def to_dict(self): data = {'file_id': self.file_id, 'width': self.width, 'height': self.height, - 'thumb': self.thumb.to_data()} + 'thumb': self.thumb.to_dict()} if self.file_size: data['file_size'] = self.file_size return data diff --git a/telegram/update.py b/telegram/update.py index 072207bae..8594c6d91 100644 --- a/telegram/update.py +++ b/telegram/update.py @@ -22,8 +22,8 @@ class Update(TelegramObject): return Update(update_id=data.get('update_id', None), message=message) - def to_data(self): + def to_dict(self): data = {'update_id': self.update_id} if self.message: - data['message'] = self.message.to_data() + data['message'] = self.message.to_dict() return data diff --git a/telegram/user.py b/telegram/user.py index fd7098d31..d65379fa0 100644 --- a/telegram/user.py +++ b/telegram/user.py @@ -30,7 +30,7 @@ class User(TelegramObject): last_name=data.get('last_name', None), username=data.get('username', None)) - def to_data(self): + def to_dict(self): data = {'id': self.id, 'first_name': self.first_name} if self.last_name: diff --git a/telegram/userprofilephotos.py b/telegram/userprofilephotos.py index c6cb99ffe..185aec40b 100644 --- a/telegram/userprofilephotos.py +++ b/telegram/userprofilephotos.py @@ -24,12 +24,12 @@ class UserProfilePhotos(TelegramObject): return UserProfilePhotos(total_count=data.get('total_count', None), photos=photos) - def to_data(self): + def to_dict(self): data = {} if self.total_count: data['total_count'] = self.total_count if self.photos: data['photos'] = [] for photo in self.photos: - data['photos'].append([x.to_data() for x in photo]) + data['photos'].append([x.to_dict() for x in photo]) return data diff --git a/telegram/video.py b/telegram/video.py index 1ea192f56..123cb1a27 100644 --- a/telegram/video.py +++ b/telegram/video.py @@ -40,12 +40,13 @@ class Video(TelegramObject): file_size=data.get('file_size', None), caption=data.get('caption', None)) - def to_data(self): + def to_dict(self): data = {'file_id': self.file_id, 'width': self.width, 'height': self.height, - 'duration': self.duration, - 'thumb': self.thumb.to_data()} + 'duration': self.duration} + if self.thumb: + data['thumb'] = self.thumb.to_dict() if self.mime_type: data['mime_type'] = self.mime_type if self.file_size: