Last active
March 22, 2018 13:23
-
-
Save JialunC/3a678441fcaf2778d693c1cbc47a8b20 to your computer and use it in GitHub Desktop.
Async_code_1 for downloading json (w/o aiofiles)
This file contains hidden or 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and the same with
aiofiles
? ;-)