Created
September 7, 2023 22:35
-
-
Save jackwakefield/08b230cc9d0db0bf1a6abd2e19a0a655 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 aiohttp | |
import asyncio | |
import json | |
headers = { | |
"Content-Type": "application/json", | |
"Accept": "application/json", | |
"X-Api-Key": "aa-live-******" | |
} | |
base_data = { | |
"language": "en", | |
"region": "us", | |
"depth": 2, | |
"fresh": True, | |
"async": False, | |
"notify_webhooks": False | |
} | |
async def fetch(fruit, session): | |
data = base_data.copy() | |
data["terms"] = [fruit] | |
async with session.post("https://alsoaskedapi.com/v1/search", headers=headers, json=data) as response: | |
return await response.json() | |
async def main(): | |
fruits = ["apples", "bananas", "cherries", "dates", "figs", "grapes", "mangoes", "oranges", "pears", "strawberries"] | |
async with aiohttp.ClientSession() as session: | |
results = await asyncio.gather(*(fetch(fruit, session) for fruit in fruits)) | |
print(results) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment