Last active
October 11, 2017 02:04
-
-
Save sebnapi/176dd48be5babc858620c34cc45d2369 to your computer and use it in GitHub Desktop.
Elegant Time-Series Raw Data Download
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
# Python 3 | |
# from urllib.parse import urljoin | |
# Python 2.7 | |
from urlparse import urljoin | |
from datetime import * | |
url = "http://xxx.com/data/" | |
today = datetime.now().date() | |
yesterday = today - timedelta(days=1) | |
path = lambda y,m,d: "%s/data-%s-%s-%s.csv.bz" % (y,y,m,d) | |
download_url = lambda y, m, d: urljoin(url, path(y, m, d)) | |
everyday = [] | |
while yesterday >= date(2017, 9, 11): | |
everyday.append(download_url(yesterday.strftime("%Y"), yesterday.strftime("%m"), yesterday.strftime("%d"))) | |
yesterday -= timedelta(days=1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment