Skip to content

Instantly share code, notes, and snippets.

@sebnapi
Last active October 11, 2017 02:04
Show Gist options
  • Save sebnapi/176dd48be5babc858620c34cc45d2369 to your computer and use it in GitHub Desktop.
Save sebnapi/176dd48be5babc858620c34cc45d2369 to your computer and use it in GitHub Desktop.
Elegant Time-Series Raw Data Download
# 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