add support for multiple countries per provider
This commit is contained in:
parent
955d3780d2
commit
46bc95c34f
@ -2,6 +2,7 @@
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import base64
|
||||
import logging
|
||||
import asyncio
|
||||
@ -66,18 +67,41 @@ class ProxyElem():
|
||||
return urls
|
||||
|
||||
proxies = {}
|
||||
new_providers = {}
|
||||
for key in providers:
|
||||
proxies[key] = []
|
||||
expr = re.compile(f'{key}_([a-z][a-z])?[0-9]+', re.IGNORECASE)
|
||||
matches = list(filter(expr.match, os.environ.keys()))
|
||||
current = []
|
||||
for i in range(0,9):
|
||||
proxy = os.environ.get(f'{key}_proxy{i}'.upper())
|
||||
current_keys = set()
|
||||
current_keys.add(key)
|
||||
countries = []
|
||||
empty = True
|
||||
for match in matches:
|
||||
country_groups = expr.match(match.lower()).groups()
|
||||
country = None
|
||||
pos = len(country_groups) - 1
|
||||
if pos >= 0:
|
||||
country = country_groups[pos]
|
||||
current_keys.add(f'{key}_{country}')
|
||||
proxy = os.environ.get(match)
|
||||
if proxy is not None:
|
||||
current.append(proxy)
|
||||
if len(current) == 0:
|
||||
proxies[key].append(ProxyElem(None))
|
||||
else:
|
||||
for proxy in current:
|
||||
proxies[key].append(ProxyElem(proxy))
|
||||
countries.append(country)
|
||||
if country is None:
|
||||
empty = False
|
||||
for elem in current_keys:
|
||||
proxies[elem] = []
|
||||
new_providers[elem] = providers[key]
|
||||
print(proxies)
|
||||
for proxy, country in zip(current, countries):
|
||||
new_key = key
|
||||
if country is not None:
|
||||
new_key = f'{key}_{country}'
|
||||
proxies[new_key].append(ProxyElem(proxy))
|
||||
for elem in current_keys:
|
||||
if len(proxies[elem]) == 0:
|
||||
proxies[elem].append(ProxyElem(None))
|
||||
providers = new_providers
|
||||
|
||||
proxy_keys = []
|
||||
for proxy_provider in proxies.values():
|
||||
|
Loading…
Reference in New Issue
Block a user