Resolve merge conflicts.

This commit is contained in:
pieter 2015-07-02 13:54:45 +02:00
commit 36ba21643b
4 changed files with 26 additions and 2 deletions

View File

@ -165,4 +165,4 @@ def listener1(*messages):
- [x] sendLocation
- [x] sendChatAction
- [x] getUserProfilePhotos
- [ ] getUpdat(contact and chat message not yet)
- [ ] getUpdat(chat message not yet)

View File

@ -2,7 +2,7 @@
from setuptools import setup
setup(name='pyTelegramBotAPI',
version='0.1.8',
version='0.1.9',
description='Python Telegram bot api. ',
author='eternnoir',
author_email='eternnoir@gmail.com',
@ -16,6 +16,7 @@ setup(name='pyTelegramBotAPI',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Environment :: Console',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
]

View File

@ -28,6 +28,7 @@ class JsonSerializable:
Subclasses of this class are guaranteed to be able to be converted to JSON format.
All subclasses of this class must override to_json.
"""
def to_json(self):
"""
Returns a JSON string representation of this class.
@ -134,6 +135,9 @@ class Message(JsonDeserializable):
if 'location' in obj:
opts['location'] = Location.de_json(obj['location'])
content_type = 'location'
if 'contact' in obj:
opts['contact'] = Contact.de_json(json.dumps(obj['contact']))
content_type = 'contact'
return Message(message_id, from_user, date, chat, content_type, opts)
@classmethod
@ -280,6 +284,18 @@ class Video(JsonDeserializable):
class Contact:
@classmethod
def de_json(cls, json_string):
obj = json.loads(json_string)
phone_number = obj['phone_number']
first_name = obj['first_name']
last_name = None
if 'last_name' in obj:
last_name = obj['last_name']
if 'user_id' in obj:
user_id = obj['user_id']
return Contact(phone_number, first_name, last_name, user_id)
def __init__(self, phone_number, first_name, last_name=None, user_id=None):
self.phone_number = phone_number
self.first_name = first_name

View File

@ -88,3 +88,10 @@ def test_json_UserProfilePhotos():
upp = types.UserProfilePhotos.de_json(json_string)
assert upp.photos[0][0].width == 160
assert upp.photos[0][-1].height == 800
def test_json_contact():
json_string = r'{"phone_number":"00011111111","first_name":"dd","last_name":"ddl","user_id":8633}'
contact = types.Contact.de_json(json_string)
assert contact.first_name == 'dd'
assert contact.last_name == 'ddl'