proxybroker2 icon indicating copy to clipboard operation
proxybroker2 copied to clipboard

Serve proxies with one line of code

Open ghost opened this issue 5 years ago • 1 comments

I think the code to get a list of proxies should be as simple as possible. So just make something like proxies = Broker.get_proxies(n). Maybe an optional parameter with the format of the strings.

def getProxies(n: int) -> List[str]:
    '''Return a list of n working proxies
    '''
    async def show(proxies):
        p = []
        while True:
                proxy = await proxies.get()
                if proxy is None: break
                p.append(f'{proxy.host}:{proxy.port}')
        return p
 
    proxies = asyncio.Queue()
    broker = Broker(proxies)
    tasks = asyncio.gather(broker.find(types=['HTTPS'], limit=n), show(proxies))
    loop = asyncio.get_event_loop()
    return loop.run_until_complete(tasks)[1]

ghost avatar Dec 01 '20 10:12 ghost

@ajr-dev thanks for your feedback :smiley: Would you like to send a PR?

bluet avatar Apr 07 '21 22:04 bluet