Skip to content

Commit

Permalink
update and shuffle the proxy list daily
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrtye committed Oct 8, 2024
1 parent 1f5dd03 commit d7ef6ae
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions novel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d7ef6ae

Please sign in to comment.