Created
November 3, 2018 04:36
-
-
Save abangfarhan/17458e3dd1499cde797a0a354ab36c61 to your computer and use it in GitHub Desktop.
Download all Data for Tsay's Financial Time Series Book
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
#!/usr/bin/env python3 | |
""" | |
Python script to download and save all .txt and .dat data for the book | |
Analysis of Financial Time Series (3rd edition) by Ruey S. Tsay | |
""" | |
from requests import get | |
import re | |
from urllib.request import urlretrieve | |
from urllib.error import HTTPError | |
url = 'http://faculty.chicagobooth.edu/ruey.tsay/teaching/fts3/' | |
res = get(url) | |
raw = res.content.decode('UTF-16LE') | |
txt_data = re.findall('[a-zA-Z0-9-]+\.txt', raw) | |
dat_data = re.findall('[a-zA-Z0-9-]+\.dat', raw) | |
all_data = txt_data + dat_data | |
data = set(all_data) | |
for fname in data: | |
print('Downloading ' + fname) | |
try: | |
urlretrieve(url + fname, fname) | |
except HTTPError: | |
print(fname + ' cannot be downloaded') | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment