Skip to content

Instantly share code, notes, and snippets.

@diogommartins
Last active November 4, 2018 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogommartins/3666e8e0d60a7d4260263f498a1446e3 to your computer and use it in GitHub Desktop.
Save diogommartins/3666e8e0d60a7d4260263f498a1446e3 to your computer and use it in GitHub Desktop.
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