-
-
Save amamaiev/dfc7032d8ea89f65cc9757c6ddee56e0 to your computer and use it in GitHub Desktop.
Download Quandl WIKI EOD stock prices
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 requests | |
import zip | |
filename = 'wiki_prices.zip' | |
# Fetch the wiki_prices.zip file | |
r = requests.get( | |
'https://www.quandl.com/api/v3/datatables/WIKI/PRICES?qopts.export=true&api_key=YOUR-API-KEY') | |
resp = r.json() | |
link = r.json()['datatable_bulk_download']['file']['link'] | |
r = requests.get(link, stream=True) | |
# Write the file to your local filesystem | |
with open(filename, 'wb') as f: | |
for chunk in download.iter_content(chunk_size=1024): | |
if chunk: # filter out keep-alive new chunks | |
f.write(chunk) | |
# Eventually uncompress file to get a CSV file | |
zip_ref = zipfile.ZipFile(filename, 'r') | |
zip_ref.extractall('.') | |
zip_ref.close() | |
logger.info('Renaming file') | |
os.rename(zip_ref.filelist[0].filename, 'wiki_prices.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment