persist proxy

This commit is contained in:
Roy Olav Purser 2021-05-11 15:33:27 +02:00
parent 9cf3f9a3f4
commit 82c6b57907
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import random
import json import json
import urllib.parse import urllib.parse
import re import re
@ -172,16 +171,16 @@ class MainHandler(tornado.web.RequestHandler):
if isinstance(proxy_list_orig, list): if isinstance(proxy_list_orig, list):
proxy_list = proxy_list_orig.copy() proxy_list = proxy_list_orig.copy()
if isinstance(proxy_list, list): if isinstance(proxy_list, list):
rand = random.SystemRandom()
rand.shuffle(proxy_list)
for proxy_temp in proxy_list: for proxy_temp in proxy_list:
try: try:
resp = requests.head(src, allow_redirects=True, proxies=proxy_temp.req, timeout=(0.1, 2.0)) resp = requests.head(src, allow_redirects=True, proxies=proxy_temp.req, timeout=(1, 2))
if resp is not None: if resp is not None:
src = resp.url src = resp.url
except Exception as e: except Exception as e:
print(e) print(e)
else: else:
proxy_list.remove(proxy_temp)
proxies[provider] = [proxy_temp] + proxy_list
proxy = proxy_temp proxy = proxy_temp
if proxy is not None: if proxy is not None:
try: try: