Skip to content

Instantly share code, notes, and snippets.

@zzl221000
Created July 28, 2023 09:01
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 zzl221000/6d2f586a16f058e5502907a877104f79 to your computer and use it in GitHub Desktop.
Save zzl221000/6d2f586a16f058e5502907a877104f79 to your computer and use it in GitHub Desktop.
aiostream example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import aiohttp
import asyncio
from aiostream import operator, pipe
api = ''
@operator
def get_lines_iterator(filename):
with open(filename) as fp:
for line in fp:
yield line
async def main():
async with aiohttp.ClientSession() as session:
async def delete_file(uri: str) -> int:
headers = {'Authorization': 'xxxxxxxxxxx'}
url = api + uri
async with session.delete(url, headers=headers) as response:
return uri, response.status
await (get_lines_iterator('uris.txt') | pipe.map(delete_file, task_limit=100) | pipe.print())
if __name__ == '__main__':
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment