Last active
February 9, 2018 19:49
-
-
Save pbazard/869cd8428dcc6cab1e0c22c943999b4c 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 | |
# Quandl file name | |
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 to get a CSV file | |
zip_ref = zipfile.ZipFile(filename, 'r') | |
zip_ref.extractall('.') | |
zip_ref.close() | |
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
Hey, thanks I wondered how I could automate the download of this file !