Created
July 28, 2023 09:01
-
-
Save zzl221000/6d2f586a16f058e5502907a877104f79 to your computer and use it in GitHub Desktop.
aiostream example
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
#!/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