Skip to content

Instantly share code, notes, and snippets.

@jackwakefield
Created September 7, 2023 22:35
Show Gist options
  • Save jackwakefield/08b230cc9d0db0bf1a6abd2e19a0a655 to your computer and use it in GitHub Desktop.
Save jackwakefield/08b230cc9d0db0bf1a6abd2e19a0a655 to your computer and use it in GitHub Desktop.
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