当前位置: 首页>>代码示例>>Python>>正文


Python telebot.logger方法代码示例

本文整理汇总了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'] 
开发者ID:MagicNews,项目名称:ASMagic,代码行数:22,代码来源:apihelper.py

示例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'] 
开发者ID:MagicNews,项目名称:ASMagic,代码行数:22,代码来源:apihelper.py

示例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'] 
开发者ID:eternnoir,项目名称:pyTelegramBotAPI,代码行数:32,代码来源:apihelper.py

示例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 
开发者ID:skgsergio,项目名称:dogefy-tg-bot,代码行数:52,代码来源:dogefybot.py


注:本文中的telebot.logger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。