Last active
October 8, 2020 03:12
-
-
Save JialunC/834d015552d5d6e402894bbd9fb48e89 to your computer and use it in GitHub Desktop.
Async_code_2 for downloading json (with 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 def store_json_2(symbol): | |
print(f'============downloading {symbol} json data ============') | |
payload = { | |
'function': 'TIME_SERIES_DAILY_ADJUSTED', | |
'symbol': symbol, | |
'outputsize': 'full', | |
'apikey': config.ALPHA_API_KEY, | |
# AA api default data type is json, another option is csv | |
'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() | |
async with aiofiles.open(f'./data/data_{symbol}.json', 'w') as outfile: | |
await outfile.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment