diff --git a/novel/main.py b/novel/main.py index cae4f80..775bb54 100644 --- a/novel/main.py +++ b/novel/main.py @@ -47,20 +47,21 @@ def load_proxies(): proxies = [] response = requests.get(PROXY_URL) - if response.status_code == 200: - file_content = response.text - ip_list = file_content.strip().split("\n") + if response.status_code != 200: + raise Exception("Proxy server not responding") - for ip_entry in ip_list: - ip, port, username, password = ip_entry.rstrip("\r").split(":") - if ip not in load_unavailable_ips(): - proxies.append((ip, port, username, password)) + file_content = response.text + ip_list = file_content.strip().split("\n") - if len(proxies) == 0: - raise Exception("No available proxy") + for ip_entry in ip_list: + ip, port, username, password = ip_entry.rstrip("\r").split(":") + if ip not in load_unavailable_ips(): + proxies.append((ip, port, username, password)) - else: - raise Exception("Proxy server not responding") + if len(proxies) == 0: + raise Exception("No available proxy") + + random.shuffle(proxies) return proxies @@ -243,10 +244,16 @@ def start_api_server(): if index == len(proxies) - 1: raise e - last_updated_time = time.time() + current_time = time.time() + if time.localtime(current_time).tm_mday != time.localtime(last_updated_time).tm_mday: + proxies = load_proxies() + last_updated_time = current_time time.sleep(sleep_interval) i = (i + 1) % len(books) + except SystemExit: + raise + except Exception as e: bot.send_message( TELEBOT_USER_ID, "Novel monitor encountered unexpected exception"