-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproxyhandler.py
More file actions
27 lines (22 loc) · 766 Bytes
/
proxyhandler.py
File metadata and controls
27 lines (22 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from itertools import cycle
import random
proxies_file = 'proxies.txt'
def read_proxies(file):
with open(file) as txt_file:
proxies = txt_file.read().splitlines()
return proxies
def proxy_parse(proxy):
proxy_parts = proxy.split(':')
if len(proxy_parts) == 2:
ip, port = proxy_parts
formatted_proxy = {'http': f'https://{ip}:{port}/',}
elif len(proxy_parts) == 4:
ip, port, user, password = proxy_parts
formatted_proxy = {'http': f'https://{user}:{password}@{ip}:{port}/',}
formatted_proxy = formatted_proxy['http']
return formatted_proxy
def proxy():
proxies = read_proxies(proxies_file)
proxy_rotation = random.choice(proxies)
proxy = proxy_parse(proxy_rotation)
return proxy