add support for multiple countries per provider
This commit is contained in:
		@@ -2,6 +2,7 @@
 | 
				
			|||||||
import json
 | 
					import json
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
import base64
 | 
					import base64
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import asyncio
 | 
					import asyncio
 | 
				
			||||||
@@ -66,18 +67,41 @@ class ProxyElem():
 | 
				
			|||||||
            return urls
 | 
					            return urls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
proxies = {}
 | 
					proxies = {}
 | 
				
			||||||
 | 
					new_providers = {}
 | 
				
			||||||
for key in 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 = []
 | 
					    current = []
 | 
				
			||||||
    for i in range(0,9):
 | 
					    current_keys = set()
 | 
				
			||||||
        proxy = os.environ.get(f'{key}_proxy{i}'.upper())
 | 
					    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:
 | 
					        if proxy is not None:
 | 
				
			||||||
            current.append(proxy)
 | 
					            current.append(proxy)
 | 
				
			||||||
    if len(current) == 0:
 | 
					            countries.append(country)
 | 
				
			||||||
        proxies[key].append(ProxyElem(None))
 | 
					            if country is None:
 | 
				
			||||||
    else:
 | 
					                empty = False
 | 
				
			||||||
        for proxy in current:
 | 
					    for elem in current_keys:
 | 
				
			||||||
            proxies[key].append(ProxyElem(proxy))
 | 
					        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 = []
 | 
					proxy_keys = []
 | 
				
			||||||
for proxy_provider in proxies.values():
 | 
					for proxy_provider in proxies.values():
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user