Last active
November 4, 2018 05:23
-
-
Save diogommartins/3666e8e0d60a7d4260263f498a1446e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from http import HTTPStatus | |
from typing import AsyncIterator | |
from aiohttp import ClientSession | |
WORDLIST_URL = "https://s3.amazonaws.com/diogo.martins/public/portuguese-brazil.txt" | |
async def stream_wordlist(limit: int=None) -> AsyncIterator[str]: | |
async with ClientSession() as session: | |
async with session.get(WORDLIST_URL) as response: | |
i = 0 | |
async for row in response.content: | |
yield row.rstrip().decode('utf-8') | |
i += 1 | |
if i == limit: | |
break | |
async def produce_messages(): | |
async for word in stream_wordlist(limit=10000): | |
print(word) | |
asyncio.get_event_loop().run_until_complete(produce_messages()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment