mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 20:13:57 +01:00
code and comment cleanup
This commit is contained in:
parent
e489ff0898
commit
bd4fc0ad86
|
@ -15,11 +15,14 @@ load_dotenv()
|
||||||
USE_PROXY_LIST = os.getenv('USE_PROXY_LIST', 'False').lower() == 'true'
|
USE_PROXY_LIST = os.getenv('USE_PROXY_LIST', 'False').lower() == 'true'
|
||||||
|
|
||||||
class Proxy:
|
class Proxy:
|
||||||
"""Represents a proxy. The type can be either http, https, socks4 or socks5.
|
"""
|
||||||
You can also pass a url, which will be parsed into the other attributes.
|
### Represents a proxy.
|
||||||
URL format:
|
The type can be either http, https, socks4 or socks5.
|
||||||
|
You can also pass a url, which will be parsed into the other attributes.
|
||||||
|
|
||||||
|
URL format:
|
||||||
[type]://[username:password@]host:port
|
[type]://[username:password@]host:port
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
url: str=None,
|
url: str=None,
|
||||||
|
@ -73,28 +76,27 @@ URL format:
|
||||||
proxy_type=proxy_types[self.proxy_type],
|
proxy_type=proxy_types[self.proxy_type],
|
||||||
host=self.ip_address,
|
host=self.ip_address,
|
||||||
port=self.port,
|
port=self.port,
|
||||||
rdns=False, # remote DNS
|
rdns=False,
|
||||||
username=self.username,
|
username=self.username,
|
||||||
password=self.password
|
password=self.password
|
||||||
)
|
)
|
||||||
|
|
||||||
# load proxies from files
|
## Load proxies from their files
|
||||||
|
|
||||||
proxies_in_files = []
|
proxies_in_files = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for proxy_type in ['http', 'socks4', 'socks5']:
|
for proxy_type in ['http', 'socks4', 'socks5']:
|
||||||
with open(f'secret/proxies/{proxy_type}.txt') as f:
|
with open(f'secret/proxies/{proxy_type}.txt') as f:
|
||||||
for line in f.readlines():
|
for line in f:
|
||||||
if line.strip() and not line.strip().startswith('#'):
|
clean_line = line.split('#', 1)[0].strip()
|
||||||
if '#' in line:
|
if clean_line:
|
||||||
line = line.split('#')[0]
|
proxies_in_files.append(f'{proxy_type}://{clean_line}')
|
||||||
|
|
||||||
proxies_in_files.append(f'{proxy_type}://{line.strip()}')
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Proxy lists support
|
## Manages the proxy list
|
||||||
|
|
||||||
class ProxyLists:
|
class ProxyLists:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -104,8 +106,11 @@ class ProxyLists:
|
||||||
self.connector = aiohttp_socks.ChainProxyConnector.from_urls(proxies_in_files)
|
self.connector = aiohttp_socks.ChainProxyConnector.from_urls(proxies_in_files)
|
||||||
|
|
||||||
def get_proxy() -> Proxy:
|
def get_proxy() -> Proxy:
|
||||||
"""Returns a Proxy object. The proxy is either from the proxy list or from the environment variables.
|
"""
|
||||||
"""
|
### Returns a Proxy object
|
||||||
|
The proxy is either from the proxy list or from the environment variables.
|
||||||
|
"""
|
||||||
|
|
||||||
if USE_PROXY_LIST:
|
if USE_PROXY_LIST:
|
||||||
return ProxyLists().get_random
|
return ProxyLists().get_random
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue