Skip to content

Instantly share code, notes, and snippets.

@JialunC
Last active March 22, 2018 13:23
Show Gist options
  • Save JialunC/3a678441fcaf2778d693c1cbc47a8b20 to your computer and use it in GitHub Desktop.
Save JialunC/3a678441fcaf2778d693c1cbc47a8b20 to your computer and use it in GitHub Desktop.
Async_code_1 for downloading json (w/o aiofiles)
import asyncio
import aiohttp
import json
# import aiofiles
import config
# ============== async function 1 ===============
async def store_json_1(symbol):
print(f'============downloading {symbol} json data ============')
payload = {
'function': 'TIME_SERIES_DAILY_ADJUSTED',
'symbol': symbol,
'outputsize': 'full',
'apikey': config.ALPHA_API_KEY,
'datatype': 'json'
}
async with aiohttp.ClientSession() as session:
async with session.get('https://www.alphavantage.co/query?', params=payload) as r:
data = await r.text()
with open(f'./data/data_{symbol}.json', 'w') as outfile:
json.dump(data, outfile)
@elmcrest
Copy link

and the same with aiofiles? ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment