From 702ce5906d426e3fde801f26eccdad79a42ec8a3 Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Fri, 29 Oct 2021 01:16:09 +0300 Subject: [PATCH] change int to float in proxieng logic --- utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils.py b/utils.py index c405510..2252dd8 100644 --- a/utils.py +++ b/utils.py @@ -18,9 +18,9 @@ NEWS_ENDPOINT = 'news/list' # proxy: last request time # ssh -C2 -T -n -N -D 2081 patagonia -PROXIES_DICT: list[dict] = [{'url': 'socks5://127.0.0.1:2080', 'last_req': int(time.time())}, - {'url': 'socks5://127.0.0.1:2081', 'last_req': int(time.time())}, - {'url': None, 'last_req': int(time.time())}] +PROXIES_DICT: list[dict] = [{'url': 'socks5://127.0.0.1:2080', 'last_req': time.time()}, + {'url': 'socks5://127.0.0.1:2081', 'last_req': time.time()}, + {'url': None, 'last_req': time.time()}] class FAPIDownForMaintenance(Exception): @@ -48,14 +48,14 @@ def proxied_request(url: str, method: str = 'get', **kwargs) -> requests.Respons """ global PROXIES_DICT - TIME_BETWEEN_REQUESTS: int = 3 + TIME_BETWEEN_REQUESTS: float = 3.0 selected_proxy = min(PROXIES_DICT, key=lambda x: x['last_req']) logger.debug(f'Using {selected_proxy["url"]} proxy') # let's detect how much we have to wait - time_to_sleep: int = int(time.time()) - selected_proxy['last_req'] + time_to_sleep: float = time.time() - selected_proxy['last_req'] if 0 < time_to_sleep <= TIME_BETWEEN_REQUESTS: logger.debug(f'Sleeping {time_to_sleep} s') @@ -76,7 +76,7 @@ def proxied_request(url: str, method: str = 'get', **kwargs) -> requests.Respons for i, proxy in enumerate(PROXIES_DICT): if proxy['url'] == selected_proxy["url"]: - PROXIES_DICT[i]['last_req'] = int(time.time()) + PROXIES_DICT[i]['last_req'] = time.time() break