1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Add User json convert.

This commit is contained in:
eternnoir 2015-06-26 15:15:30 +08:00
parent fcbd4e3849
commit 518fed5bc1

View File

@ -20,7 +20,23 @@ ReplyKeyboardHide
ForceReply
"""
import json
class User:
@classmethod
def de_json(cls, json_string):
obj = json.loads(json_string)
id = obj['id']
first_name = obj['first_name']
last_name = None
username = None
if 'last_name' in obj:
last_name = obj['last_name']
if 'username' in obj:
username = obj['username']
return User(id, first_name, last_name, username)
def __init__(self, id, first_name, last_name=None, username=None):
self.id = id
self.first_name = first_name