本文整理匯總了Python中telebot.logger方法的典型用法代碼示例。如果您正苦於以下問題:Python telebot.logger方法的具體用法?Python telebot.logger怎麽用?Python telebot.logger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類telebot
的用法示例。
在下文中一共展示了telebot.logger方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _pwr_make_request
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import logger [as 別名]
def _pwr_make_request(token, method_name, method='get', params=None, files=None, base_url=PWRAPI_URL):
"""
Makes a request to the Telegram API.
:param token: The bot's API token. (Created with @BotFather)
:param method_name: Name of the API method to be called. (E.g. 'getUpdates')
:param method: HTTP method to be used. Defaults to 'get'.
:param params: Optional parameters. Should be a dictionary with key-value pairs.
:param files: Optional files.
:return: The result parsed to a JSON dictionary.
"""
request_url = base_url.format(token, method_name)
logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files))
read_timeout = READ_TIMEOUT
connect_timeout = CONNECT_TIMEOUT
if params:
if 'timeout' in params: read_timeout = params['timeout'] + 10
if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10
result = requests.request(method, request_url, params=params, files=files, timeout=(connect_timeout, read_timeout))
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
return _check_result(method_name, result)['result']
示例2: _make_request
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import logger [as 別名]
def _make_request(token, method_name, method='get', params=None, files=None, base_url=API_URL):
"""
Makes a request to the Telegram API.
:param token: The bot's API token. (Created with @BotFather)
:param method_name: Name of the API method to be called. (E.g. 'getUpdates')
:param method: HTTP method to be used. Defaults to 'get'.
:param params: Optional parameters. Should be a dictionary with key-value pairs.
:param files: Optional files.
:return: The result parsed to a JSON dictionary.
"""
request_url = base_url.format(token, method_name)
logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files))
read_timeout = READ_TIMEOUT
connect_timeout = CONNECT_TIMEOUT
if params:
if 'timeout' in params: read_timeout = params['timeout'] + 10
if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10
result = requests.request(method, request_url, params=params, files=files, timeout=(connect_timeout, read_timeout))
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
return _check_result(method_name, result)['result']
示例3: _make_request
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import logger [as 別名]
def _make_request(token, method_name, method='get', params=None, files=None):
"""
Makes a request to the Telegram API.
:param token: The bot's API token. (Created with @BotFather)
:param method_name: Name of the API method to be called. (E.g. 'getUpdates')
:param method: HTTP method to be used. Defaults to 'get'.
:param params: Optional parameters. Should be a dictionary with key-value pairs.
:param files: Optional files.
:return: The result parsed to a JSON dictionary.
"""
if API_URL is None:
request_url = "https://api.telegram.org/bot{0}/{1}".format(token, method_name)
else:
request_url = API_URL.format(token, method_name)
logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files))
read_timeout = READ_TIMEOUT
connect_timeout = CONNECT_TIMEOUT
if files and format_header_param:
fields.format_header_param = _no_encode(format_header_param)
if params:
if 'timeout' in params:
read_timeout = params.pop('timeout') + 10
if 'connect-timeout' in params:
connect_timeout = params.pop('connect-timeout') + 10
result = _get_req_session().request(
method, request_url, params=params, files=files,
timeout=(connect_timeout, read_timeout), proxies=proxy)
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
return _check_result(method_name, result)['result']
示例4: handle_photo
# 需要導入模塊: import telebot [as 別名]
# 或者: from telebot import logger [as 別名]
def handle_photo(m):
# Chat id, for sending actions and file
cid = m.chat.id
# Search the biggest photo (avoid thumbnails)
f_id = None
b_size = 0
for p in m.photo:
t_size = p.height * p.width
if t_size > b_size:
b_size = t_size
f_id = p.file_id
# Download and write the file
f_info = bot.get_file(f_id)
f_download = bot.download_file(f_info.file_path)
with open(f_id, 'wb') as f:
f.write(f_download)
# Dogefy all the faces!!
n_faces = dogefy(f_id)
if n_faces > 0:
# Send "uploading photo" action since can take a few seconds
bot.send_chat_action(cid, 'upload_photo')
# Upload the photo and do it as a reply
bot.send_photo(cid,
open(f_id+img_ext, 'rb'),
caption='Very wow, such doge%s.' %
('s' if n_faces > 1 else ''))
try:
os.unlink(f_id+img_ext)
except Exception as e: # You shouldn't do this never but... *effort*
logger.error(e)
# If there is no faces and is not a group tell the user
elif cid > 0:
bot.send_chat_action(cid, 'typing')
bot.send_message(cid, 'Very fail, such sad, no faces.')
try:
os.unlink(f_id)
except Exception as e: # You shouldn't do this never but... *effort*
logger.error(e)
# Help/Start handler