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


Python request.post函数代码示例

本文整理汇总了Python中telegram.utils.request.post函数的典型用法代码示例。如果您正苦于以下问题:Python post函数的具体用法?Python post怎么用?Python post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了post函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _post_message

    def _post_message(url, data, kwargs, timeout=None, network_delay=2.):
        """Posts a message to the telegram servers.

        Returns:
            telegram.Message

        """
        if not data.get('chat_id'):
            raise TelegramError('Invalid chat_id')

        if kwargs.get('reply_to_message_id'):
            reply_to_message_id = kwargs.get('reply_to_message_id')
            data['reply_to_message_id'] = reply_to_message_id

        if kwargs.get('reply_markup'):
            reply_markup = kwargs.get('reply_markup')
            if isinstance(reply_markup, ReplyMarkup):
                data['reply_markup'] = reply_markup.to_json()
            else:
                data['reply_markup'] = reply_markup

        result = request.post(url, data, timeout=timeout,
                              network_delay=network_delay)

        if result is True:
            return result

        return Message.de_json(result)
开发者ID:sensitiveio,项目名称:python-telegram-bot,代码行数:28,代码来源:bot.py

示例2: unbanChatMember

    def unbanChatMember(self, chat_id, user_id, **kwargs):
        """Use this method to unban a previously kicked user in a supergroup.
        The user will not return to the group automatically, but will be able
        to join via link, etc. The bot must be an administrator in the group
        for this to work.

        Args:
          chat_id:
            Unique identifier for the target group or username of the target
            supergroup (in the format @supergroupusername).
          user_id:
            Unique identifier of the target user.

        Keyword Args:
            timeout (Optional[float]): If this value is specified, use it as
                the definitive timeout (in seconds) for urlopen() operations.

        Returns:
            bool: On success, `True` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """

        url = '{0}/unbanChatMember'.format(self.base_url)

        data = {'chat_id': chat_id, 'user_id': user_id}

        result = request.post(url, data, timeout=kwargs.get('timeout'))

        return result
开发者ID:jelitox,项目名称:python-telegram-bot,代码行数:32,代码来源:bot.py

示例3: decorator

        def decorator(self, *args, **kwargs):
            url, data = func(self, *args, **kwargs)

            if kwargs.get('reply_to_message_id'):
                data['reply_to_message_id'] = \
                    kwargs.get('reply_to_message_id')

            if kwargs.get('disable_notification'):
                data['disable_notification'] = \
                    kwargs.get('disable_notification')

            if kwargs.get('reply_markup'):
                reply_markup = kwargs.get('reply_markup')
                if isinstance(reply_markup, ReplyMarkup):
                    data['reply_markup'] = reply_markup.to_json()
                else:
                    data['reply_markup'] = reply_markup

            result = request.post(url, data,
                                  timeout=kwargs.get('timeout'))

            if result is True:
                return result

            return Message.de_json(result)
开发者ID:Gurzo,项目名称:python-telegram-bot,代码行数:25,代码来源:bot.py

示例4: setWebhook

    def setWebhook(self,
                   webhook_url=None,
                   certificate=None):
        """Use this method to specify a url and receive incoming updates via an
        outgoing webhook. Whenever there is an update for the bot, we will send
        an HTTPS POST request to the specified url, containing a
        JSON-serialized Update. In case of an unsuccessful request, we will
        give up after a reasonable amount of attempts.

        Args:
          url:
            HTTPS url to send updates to.
            Use an empty string to remove webhook integration

        Returns:
          True if successful else TelegramError was raised
        """
        url = '%s/setWebhook' % self.base_url

        data = {}
        if webhook_url:
            data['url'] = webhook_url
        if certificate:
            data['certificate'] = certificate

        result = request.post(url, data)

        return result
开发者ID:peczony,项目名称:python-telegram-bot,代码行数:28,代码来源:bot.py

示例5: decorator

        def decorator(self, *args, **kwargs):
            """
            decorator
            """
            url, data = func(self, *args, **kwargs)

            if not data.get('chat_id'):
                raise TelegramError('Invalid chat_id')

            if kwargs.get('reply_to_message_id'):
                reply_to_message_id = kwargs.get('reply_to_message_id')
                data['reply_to_message_id'] = reply_to_message_id

            if kwargs.get('reply_markup'):
                reply_markup = kwargs.get('reply_markup')
                if isinstance(reply_markup, ReplyMarkup):
                    data['reply_markup'] = reply_markup.to_json()
                else:
                    data['reply_markup'] = reply_markup

            result = request.post(url, data)

            if result is True:
                return result

            return Message.de_json(result)
开发者ID:peczony,项目名称:python-telegram-bot,代码行数:26,代码来源:bot.py

示例6: getFile

    def getFile(self, file_id, **kwargs):
        """Use this method to get basic info about a file and prepare it for
        downloading. For the moment, bots can download files of up to 20MB in
        size.

        Args:
          file_id:
            File identifier to get info about.

        Keyword Args:
            timeout (Optional[float]): If this value is specified, use it as
                the definitive timeout (in seconds) for urlopen() operations.

        Returns:
            :class:`telegram.File`: On success, a :class:`telegram.File`
            object is returned.

        Raises:
            :class:`telegram.TelegramError`

        """

        url = '{0}/getFile'.format(self.base_url)

        data = {'file_id': file_id}

        result = request.post(url, data, timeout=kwargs.get('timeout'))

        if result.get('file_path'):
            result['file_path'] = '%s/%s' % (self.base_file_url, result['file_path'])

        return File.de_json(result)
开发者ID:jelitox,项目名称:python-telegram-bot,代码行数:32,代码来源:bot.py

示例7: getUserProfilePhotos

    def getUserProfilePhotos(self,
                             user_id,
                             offset=None,
                             limit=100):
        """Use this method to get a list of profile pictures for a user.

        Args:
          user_id:
            Unique identifier of the target user.
          offset:
            Sequential number of the first photo to be returned. By default,
            all photos are returned. [Optional]
          limit:
            Limits the number of photos to be retrieved. Values between 1-100
            are accepted. Defaults to 100. [Optional]

        Returns:
          Returns a telegram.UserProfilePhotos object.
        """

        url = '%s/getUserProfilePhotos' % self.base_url

        data = {'user_id': user_id}

        if offset:
            data['offset'] = offset
        if limit:
            data['limit'] = limit

        result = request.post(url, data)

        return UserProfilePhotos.de_json(result)
开发者ID:peczony,项目名称:python-telegram-bot,代码行数:32,代码来源:bot.py

示例8: kickChatMember

    def kickChatMember(self, chat_id, user_id, **kwargs):
        """Use this method to kick a user from a group or a supergroup. In the
        case of supergroups, the user will not be able to return to the group
        on their own using invite links, etc., unless unbanned first. The bot
        must be an administrator in the group for this to work.

        Args:
          chat_id:
            Unique identifier for the target group or username of the target
            supergroup (in the format @supergroupusername).
          user_id:
            Unique identifier of the target user.

        Keyword Args:
            timeout (Optional[float]): If this value is specified, use it as
                the definitive timeout (in seconds) for urlopen() operations.

        Returns:
            bool: On success, `True` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """

        url = '{0}/kickChatMember'.format(self.base_url)

        data = {'chat_id': chat_id, 'user_id': user_id}

        result = request.post(url, data, timeout=kwargs.get('timeout'))

        return result
开发者ID:jelitox,项目名称:python-telegram-bot,代码行数:32,代码来源:bot.py

示例9: getFile

    def getFile(self,
                file_id):
        """Use this method to get basic info about a file and prepare it for
        downloading. For the moment, bots can download files of up to 20MB in
        size.

        Args:
          file_id:
            File identifier to get info about.

        Returns:
          Returns a telegram.File object
        """

        url = '%s/getFile' % self.base_url

        data = {'file_id': file_id}

        result = request.post(url, data)

        if result.get('file_path'):
            result['file_path'] = '%s/%s' % (self.base_file_url,
                                             result['file_path'])

        return File.de_json(result)
开发者ID:rizaon,项目名称:python-telegram-bot,代码行数:25,代码来源:bot.py

示例10: getUpdates

    def getUpdates(self,
                   offset=None,
                   limit=100,
                   timeout=0,
                   network_delay=.2):
        """Use this method to receive incoming updates using long polling.

        Args:
          offset:
            Identifier of the first update to be returned. Must be greater by
            one than the highest among the identifiers of previously received
            updates. By default, updates starting with the earliest unconfirmed
            update are returned. An update is considered confirmed as soon as
            getUpdates is called with an offset higher than its update_id.
          limit:
            Limits the number of updates to be retrieved. Values between 1-100
            are accepted. Defaults to 100.
          timeout:
            Timeout in seconds for long polling. Defaults to 0, i.e. usual
            short polling.
          network_delay:
            Additional timeout in seconds to allow the response from Telegram
            to take some time when using long polling. Defaults to 2, which
            should be enough for most connections. Increase it if it takes very
            long for data to be transmitted from and to the Telegram servers.

        Returns:
            list[:class:`telegram.Update`]: A list of :class:`telegram.Update`
            objects are returned.

        Raises:
            :class:`telegram.TelegramError`

        """

        url = '{0}/getUpdates'.format(self.base_url)

        data = {'timeout': timeout}

        if offset:
            data['offset'] = offset
        if limit:
            data['limit'] = limit

        urlopen_timeout = timeout + network_delay

        result = request.post(url, data, timeout=urlopen_timeout)

        if result:
            self.logger.debug(
                'Getting updates: %s', [u['update_id'] for u in result])
        else:
            self.logger.debug('No new updates found.')

        return [Update.de_json(x) for x in result]
开发者ID:Gurzo,项目名称:python-telegram-bot,代码行数:55,代码来源:bot.py

示例11: answerInlineQuery

    def answerInlineQuery(self,
                          inline_query_id,
                          results,
                          cache_time=None,
                          is_personal=None,
                          next_offset=None):
        """Use this method to reply to an inline query.

        Args:
            inline_query_id (str):
                Unique identifier for answered query
            results (list[InlineQueryResult]):
                A list of results for the inline query

        Keyword Args:
            cache_time (Optional[int]): The maximum amount of time the result
                of the inline query may be cached on the server
            is_personal (Optional[bool]): Pass True, if results may be cached
                on the server side only for the user that sent the query. By
                default, results may be returned to any user who sends the same
                query
            next_offset (Optional[str]): Pass the offset that a client should
                send in the next query with the same text to receive more
                results. Pass an empty string if there are no more results or
                if you don't support pagination. Offset length can't exceed 64
                bytes.

        Returns:
            A boolean if answering was successful
        """

        validate_string(inline_query_id, 'inline_query_id')
        validate_string(inline_query_id, 'next_offset')

        url = '%s/answerInlineQuery' % self.base_url

        results = [res.to_dict() for res in results]

        data = {'inline_query_id': inline_query_id,
                'results': results}

        if cache_time is not None:
            data['cache_time'] = int(cache_time)
        if is_personal is not None:
            data['is_personal'] = bool(is_personal)
        if next_offset is not None:
            data['next_offset'] = next_offset

        result = request.post(url, data)

        return result
开发者ID:sensitiveio,项目名称:python-telegram-bot,代码行数:51,代码来源:bot.py

示例12: answerCallbackQuery

    def answerCallbackQuery(self,
                            callback_query_id,
                            text=None,
                            show_alert=False,
                            **kwargs):
        """Use this method to send answers to callback queries sent from
        inline keyboards. The answer will be displayed to the user as a
        notification at the top of the chat screen or as an alert.

        Args:
            callback_query_id (str): Unique identifier for the query to be
                answered.
            text (Optional[str]): Text of the notification. If not
                specified, nothing will be shown to the user.
            show_alert (Optional[bool]): If `True`, an alert will be shown
                by the client instead of a notification at the top of the chat
                screen. Defaults to `False`.

        Keyword Args:
            timeout (Optional[float]): If this value is specified, use it as
                the definitive timeout (in seconds) for urlopen() operations.
            network_delay (Optional[float]): If using the timeout (which is
                a `timeout` for the Telegram servers operation),
                then `network_delay` as an extra delay (in seconds) to
                compensate for network latency. Defaults to 2.

        Returns:
            bool: On success, `True` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """

        url = '{0}/answerCallbackQuery'.format(self.base_url)

        data = {'callback_query_id': callback_query_id}

        if text:
            data['text'] = text
        if show_alert:
            data['show_alert'] = show_alert

        result = request.post(url, data,
                              timeout=kwargs.get('timeout'))

        return result
开发者ID:Gurzo,项目名称:python-telegram-bot,代码行数:47,代码来源:bot.py

示例13: getUpdates

    def getUpdates(self,
                   offset=None,
                   limit=100,
                   timeout=0):
        """Use this method to receive incoming updates using long polling.

        Args:
          offset:
            Identifier of the first update to be returned. Must be greater by
            one than the highest among the identifiers of previously received
            updates. By default, updates starting with the earliest unconfirmed
            update are returned. An update is considered confirmed as soon as
            getUpdates is called with an offset higher than its update_id.
          limit:
            Limits the number of updates to be retrieved. Values between 1-100
            are accepted. Defaults to 100.
          timeout:
            Timeout in seconds for long polling. Defaults to 0, i.e. usual
            short polling.

        Returns:
          A list of telegram.Update objects are returned.
        """

        url = '%s/getUpdates' % self.base_url

        data = {}
        if offset:
            data['offset'] = offset
        if limit:
            data['limit'] = limit
        if timeout:
            data['timeout'] = timeout

        result = request.post(url, data)

        if result:
            self.logger.info(
                'Getting updates: %s', [u['update_id'] for u in result])
        else:
            self.logger.info('No new updates found.')

        return [Update.de_json(x) for x in result]
开发者ID:peczony,项目名称:python-telegram-bot,代码行数:43,代码来源:bot.py

示例14: getUserProfilePhotos

    def getUserProfilePhotos(self,
                             user_id,
                             offset=None,
                             limit=100,
                             **kwargs):
        """Use this method to get a list of profile pictures for a user.

        Args:
          user_id:
            Unique identifier of the target user.
          offset:
            Sequential number of the first photo to be returned. By default,
            all photos are returned. [Optional]
          limit:
            Limits the number of photos to be retrieved. Values between 1-100
            are accepted. Defaults to 100. [Optional]

        Keyword Args:
            timeout (Optional[float]): If this value is specified, use it as
                the definitive timeout (in seconds) for urlopen() operations.

        Returns:
            list[:class:`telegram.UserProfilePhotos`]: A list of
            :class:`telegram.UserProfilePhotos` objects are returned.

        Raises:
            :class:`telegram.TelegramError`

        """

        url = '{0}/getUserProfilePhotos'.format(self.base_url)

        data = {'user_id': user_id}

        if offset:
            data['offset'] = offset
        if limit:
            data['limit'] = limit

        result = request.post(url, data,
                              timeout=kwargs.get('timeout'))

        return UserProfilePhotos.de_json(result)
开发者ID:Gurzo,项目名称:python-telegram-bot,代码行数:43,代码来源:bot.py

示例15: setWebhook

    def setWebhook(self,
                   webhook_url=None,
                   certificate=None,
                   **kwargs):
        """Use this method to specify a url and receive incoming updates via an
        outgoing webhook. Whenever there is an update for the bot, we will send
        an HTTPS POST request to the specified url, containing a
        JSON-serialized Update. In case of an unsuccessful request, we will
        give up after a reasonable amount of attempts.

        Args:
          webhook_url:
            HTTPS url to send updates to.
            Use an empty string to remove webhook integration

        Keyword Args:
            timeout (Optional[float]): If this value is specified, use it as
                the definitive timeout (in seconds) for urlopen() operations.

        Returns:
            bool: On success, `True` is returned.

        Raises:
            :class:`telegram.TelegramError`

        """

        url = '{0}/setWebhook'.format(self.base_url)

        data = {}

        if webhook_url is not None:
            data['url'] = webhook_url
        if certificate:
            data['certificate'] = certificate

        result = request.post(url, data,
                              timeout=kwargs.get('timeout'))

        return result
开发者ID:Gurzo,项目名称:python-telegram-bot,代码行数:40,代码来源:bot.py


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