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

PEP 8 & IntelliJ code clean-up.

This commit is contained in:
pieter 2015-06-30 05:54:04 +02:00
parent 34da2552dd
commit af02000534
4 changed files with 12 additions and 11 deletions

View File

@ -54,7 +54,7 @@ class TeleBot:
def __notify_update(self, new_messages): def __notify_update(self, new_messages):
for listener in self.update_listener: for listener in self.update_listener:
t = threading.Thread(target=listener, args=(new_messages)) t = threading.Thread(target=listener, args=new_messages)
t.start() t.start()
def polling(self, interval=3): def polling(self, interval=3):

View File

@ -86,7 +86,8 @@ def send_location(token, chat_id, latitude, longitude, reply_to_message_id=None,
req = requests.get(request_url, params=payload) req = requests.get(request_url, params=payload)
return check_result(method_url, req) return check_result(method_url, req)
def send_chat_action(token,chat_id,action):
def send_chat_action(token, chat_id, action):
api_url = telebot.API_URL api_url = telebot.API_URL
method_url = r'sendChatAction' method_url = r'sendChatAction'
request_url = api_url + 'bot' + token + '/' + method_url request_url = api_url + 'bot' + token + '/' + method_url
@ -94,6 +95,7 @@ def send_chat_action(token,chat_id,action):
req = requests.get(request_url, params=payload) req = requests.get(request_url, params=payload)
return check_result(method_url, req) return check_result(method_url, req)
def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None): def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None):
api_url = telebot.API_URL api_url = telebot.API_URL
method_url = get_method_by_type(data_type) method_url = get_method_by_type(data_type)

View File

@ -62,7 +62,7 @@ class Message:
def de_json(cls, json_string): def de_json(cls, json_string):
obj = json.loads(json_string) obj = json.loads(json_string)
message_id = obj['message_id'] message_id = obj['message_id']
fromUser = User.de_json(json.dumps(obj['from'])) from_user = User.de_json(json.dumps(obj['from']))
chat = Message.parse_chat(obj['chat']) chat = Message.parse_chat(obj['chat'])
date = obj['date'] date = obj['date']
content_type = None content_type = None
@ -88,7 +88,7 @@ class Message:
if 'location' in obj: if 'location' in obj:
opts['location'] = Location.de_json(json.dumps(obj['location'])) opts['location'] = Location.de_json(json.dumps(obj['location']))
content_type = 'location' content_type = 'location'
return Message(message_id, fromUser, date, chat, content_type, opts) return Message(message_id, from_user, date, chat, content_type, opts)
@classmethod @classmethod
def parse_chat(cls, chat): def parse_chat(cls, chat):
@ -262,7 +262,7 @@ class UserProfilePhotos:
class ReplyKeyboardMarkup: class ReplyKeyboardMarkup:
def __init__(self, keyboard=[], resize_keyboard=None, one_time_keyboard=None, selective=None, row_width=3): def __init__(self, resize_keyboard=None, one_time_keyboard=None, selective=None, row_width=3):
self.resize_keyboard = resize_keyboard self.resize_keyboard = resize_keyboard
self.one_time_keyboard = one_time_keyboard self.one_time_keyboard = one_time_keyboard
self.selective = selective self.selective = selective
@ -307,15 +307,14 @@ class ReplyKeyboardMarkup:
https://core.telegram.org/bots/api#replykeyboardmarkup https://core.telegram.org/bots/api#replykeyboardmarkup
:return: :return:
""" """
json_dict = {} json_dict = {'keyboard': self.keyboard}
json_dict['keyboard'] = self.keyboard if self.one_time_keyboard:
if self.one_time_keyboard != False:
json_dict['one_time_keyboard'] = True json_dict['one_time_keyboard'] = True
if self.resize_keyboard != False: if self.resize_keyboard:
json_dict['resize_keyboard'] = True json_dict['resize_keyboard'] = True
if self.selective != False: if self.selective:
json_dict['selective'] = True json_dict['selective'] = True
return json.dumps(json_dict) return json.dumps(json_dict)

View File

@ -34,7 +34,7 @@ def test_json_GroupChat():
def test_json_Document(): def test_json_Document():
json_string = r'{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_size":446}' json_string = r'{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_size":446}'
doc = types.Document.de_json(json_string) doc = types.Document.de_json(json_string)
assert doc.thumb == None assert doc.thumb is None
assert doc.file_name == 'Text File' assert doc.file_name == 'Text File'