File size: 859 Bytes
efb5a4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
import random
import asyncio

class ProxyManager:
    def __init__(self, proxies):
        if not proxies:
            raise ValueError("Proxy list cannot be empty")
        self.proxies = proxies

    async def get_proxy_url(self):
        """
        Get a random proxy URL from the list.
        """
        if not self.proxies:
            return None
        return random.choice(self.proxies)

# Example proxy list (replace with your actual proxies)
# It's recommended to use environment variables to store proxies
# For example: proxies = os.getenv("HTTP_PROXIES", "").split(",")
proxies = [
    "http://user:pass@host1:port",
    "http://user:pass@host2:port",
    "http://user:pass@host3:port",
]

proxy_manager = ProxyManager(proxies)

# For backward compatibility, if needed
async def get_proxy_url():
    return await proxy_manager.get_proxy_url()