當前位置: 首頁>>代碼示例>>Python>>正文


Python request.Request方法代碼示例

本文整理匯總了Python中telegram.utils.request.Request方法的典型用法代碼示例。如果您正苦於以下問題:Python request.Request方法的具體用法?Python request.Request怎麽用?Python request.Request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在telegram.utils.request的用法示例。


在下文中一共展示了request.Request方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: start

# 需要導入模塊: from telegram.utils import request [as 別名]
# 或者: from telegram.utils.request import Request [as 別名]
def start(self, token):
    self.voice_thread_pool = ThreadPoolExecutor(
      max_workers=config.get_config_prop("app")["voice_max_threads"]
    )
    self.photos_thread_pool = ThreadPoolExecutor(
      max_workers=config.get_config_prop("app")["photos_max_threads"]
    )

    self.misc_thread_pool = ThreadPoolExecutor(
      max_workers=2
    )

    self.queue = mq.MessageQueue()
    self.request = Request(con_pool_size=10)
    self.mqbot = self.MQBot(token, request=self.request, mqueue=self.queue)
    self.updater = Updater(bot=self.mqbot, use_context=True)
    self.dispatcher = self.updater.dispatcher
    self.__register_handlers()
    self.updater.start_polling(clean=True)
    self.updater.idle() 
開發者ID:charslab,項目名稱:TranscriberBot,代碼行數:22,代碼來源:bot.py

示例2: stop

# 需要導入模塊: from telegram.utils import request [as 別名]
# 或者: from telegram.utils.request import Request [as 別名]
def stop(self):
        """Stops the polling/webhook thread, the dispatcher and the job queue."""

        self.job_queue.stop()
        with self.__lock:
            if self.running or self.dispatcher.has_running_threads:
                self.logger.debug('Stopping Updater and Dispatcher...')

                self.running = False

                self._stop_httpd()
                self._stop_dispatcher()
                self._join_threads()

                # Stop the Request instance only if it was created by the Updater
                if self._request:
                    self._request.stop() 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:19,代碼來源:updater.py

示例3: get_proxy_request

# 需要導入模塊: from telegram.utils import request [as 別名]
# 或者: from telegram.utils.request import Request [as 別名]
def get_proxy_request(telegram_config):
        from telegram.utils.request import Request

        if telegram_config["proxy_url"].startswith("socks5"):
            urllib3_proxy_kwargs = dict()
            for key in ["username", "password"]:
                if key in telegram_config:
                    urllib3_proxy_kwargs[key] = telegram_config[key]
            return Request(
                proxy_url=telegram_config["proxy_url"],
                urllib3_proxy_kwargs=urllib3_proxy_kwargs,
            )
        elif telegram_config["proxy_url"].startswith("http"):
            cred_string = ""
            if "username" in telegram_config:
                cred_string += telegram_config["username"]
            if "password" in telegram_config:
                cred_string += ":" + telegram_config["password"]
            if len(cred_string) > 0:
                domain = telegram_config["proxy_url"].split("/")[-1].split("@")[-1]
                cred_string += "@"
                proxy_url = "http://{}{}".format(cred_string, domain)
                return Request(proxy_url=proxy_url)
            else:
                return Request(proxy_url=telegram_config["proxy_url"])
        else:
            raise Exception(
                "Proxy URL should be in format "
                "PROTOCOL://PROXY_HOST[:PROXY_PORT].\n"
                "HTTP and Socks5 are supported."
            ) 
開發者ID:IDSIA,項目名稱:sacred,代碼行數:33,代碼來源:telegram_obs.py

示例4: __init__

# 需要導入模塊: from telegram.utils import request [as 別名]
# 或者: from telegram.utils.request import Request [as 別名]
def __init__(self, token, base_url=None, base_file_url=None, request=None):
        self.token = self._validate_token(token)

        if base_url is None:
            base_url = 'https://api.telegram.org/bot'

        if base_file_url is None:
            base_file_url = 'https://api.telegram.org/file/bot'

        self.base_url = str(base_url) + str(self.token)
        self.base_file_url = str(base_file_url) + str(self.token)
        self.bot = None
        self._request = request or Request()
        self.logger = logging.getLogger(__name__) 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:16,代碼來源:bot.py

示例5: bot_start

# 需要導入模塊: from telegram.utils import request [as 別名]
# 或者: from telegram.utils.request import Request [as 別名]
def bot_start():
	# set bot
	if (proxy_url_common is None):
		bot = Bot(api_key_common)
	else:
		proxy = Request(proxy_url = proxy_url_common, urllib3_proxy_kwargs = {'username': proxy_user_common, 'password': proxy_pass_common })
		bot = Bot(token=api_key_common, request = proxy)
	return bot 
開發者ID:SergiySW,項目名稱:NanoWalletBot,代碼行數:10,代碼來源:common.py

示例6: get_bot

# 需要導入模塊: from telegram.utils import request [as 別名]
# 或者: from telegram.utils.request import Request [as 別名]
def get_bot():
    # Default size from the library, 4 workers + 4 additional
    request = Request(con_pool_size=8)
    return Bot(token=os.getenv("TG_TOKEN"), request=request) 
開發者ID:okainov,項目名稱:munich-scripts,代碼行數:6,代碼來源:utils.py

示例7: main

# 需要導入模塊: from telegram.utils import request [as 別名]
# 或者: from telegram.utils.request import Request [as 別名]
def main():
    # Start API
    # thread = threading.Thread(target=botlistapi.start_server)
    # thread.start()
    if settings.is_sentry_enabled():
        sentry_sdk.init(settings.SENTRY_URL, environment=settings.SENTRY_ENVIRONMENT)

    botchecker_context = {}

    bot_token = str(settings.BOT_TOKEN)

    botlistbot = BotListBot(
        bot_token,
        request=Request(
            read_timeout=8,
            connect_timeout=7,
            con_pool_size=max(settings.WORKER_COUNT, 4),
        ),
    )
    updater = Updater(bot=botlistbot, workers=settings.WORKER_COUNT)

    botlistbot.formatter = MarkdownFormatter(updater.bot)

    appglobals.job_queue = updater.job_queue

    # Get the dispatcher to on_mount handlers
    dp = updater.dispatcher

    routing.register(dp, None)
    basic.register(dp)

    updater.job_queue.run_repeating(admin.last_update_job, interval=3600 * 24)

    if settings.DEV:
        log.info("Starting using long polling...")
        updater.start_polling()
    else:
        log.info("Starting using webhooks...")
        updater.start_webhook(
            listen="0.0.0.0", port=settings.PORT, url_path=settings.BOT_TOKEN
        )
        updater.bot.set_webhook(
            f"https://botlistbot.herokuapp.com/{settings.BOT_TOKEN}"
        )

    log.info("Listening...")
    updater.bot.send_message(settings.DEVELOPER_ID, "Ready to rock", timeout=10)

    # Idling
    updater.idle()
    updater.stop()

    log.info("Disconnecting...") 
開發者ID:JosXa,項目名稱:BotListBot,代碼行數:55,代碼來源:main.py

示例8: __init__

# 需要導入模塊: from telegram.utils import request [as 別名]
# 或者: from telegram.utils.request import Request [as 別名]
def __init__(self,
                 token=None,
                 base_url=None,
                 workers=4,
                 bot=None,
                 user_sig_handler=None,
                 request_kwargs=None):

        if (token is None) and (bot is None):
            raise ValueError('`token` or `bot` must be passed')
        if (token is not None) and (bot is not None):
            raise ValueError('`token` and `bot` are mutually exclusive')

        self.logger = logging.getLogger(__name__)

        con_pool_size = workers + 4

        if bot is not None:
            self.bot = bot
            if bot.request.con_pool_size < con_pool_size:
                self.logger.warning(
                    'Connection pool of Request object is smaller than optimal value (%s)',
                    con_pool_size)
        else:
            # we need a connection pool the size of:
            # * for each of the workers
            # * 1 for Dispatcher
            # * 1 for polling Updater (even if webhook is used, we can spare a connection)
            # * 1 for JobQueue
            # * 1 for main thread
            if request_kwargs is None:
                request_kwargs = {}
            if 'con_pool_size' not in request_kwargs:
                request_kwargs['con_pool_size'] = con_pool_size
            self._request = Request(**request_kwargs)
            self.bot = Bot(token, base_url, request=self._request)
        self.user_sig_handler = user_sig_handler
        self.update_queue = Queue()
        self.job_queue = JobQueue(self.bot)
        self.__exception_event = Event()
        self.dispatcher = Dispatcher(
            self.bot,
            self.update_queue,
            job_queue=self.job_queue,
            workers=workers,
            exception_event=self.__exception_event)
        self.last_update_id = 0
        self.running = False
        self.is_idle = False
        self.httpd = None
        self.__lock = Lock()
        self.__threads = [] 
開發者ID:cbrgm,項目名稱:telegram-robot-rss,代碼行數:54,代碼來源:updater.py


注:本文中的telegram.utils.request.Request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。