Skip to content

Instantly share code, notes, and snippets.

@pbazard
Last active February 9, 2018 19:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pbazard/869cd8428dcc6cab1e0c22c943999b4c to your computer and use it in GitHub Desktop.
Save pbazard/869cd8428dcc6cab1e0c22c943999b4c to your computer and use it in GitHub Desktop.
Download Quandl WIKI EOD stock prices
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')
@amamaiev
Copy link

amamaiev commented Jun 2, 2017

Hey, thanks I wondered how I could automate the download of this file !

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