Skip to content

Instantly share code, notes, and snippets.

@onlurking
Last active April 8, 2018 19:40
Show Gist options
  • Save onlurking/0b0100893c89cff54fa2d72c44ad0b62 to your computer and use it in GitHub Desktop.
Save onlurking/0b0100893c89cff54fa2d72c44ad0b62 to your computer and use it in GitHub Desktop.
from datetime import datetime
from collections import namedtuple
def normalize_date(ct, m = '00', s = '00'):
"""Return formated time_object with hour - 1,
and zero-filled minutes and seconds.
>>> normalize_date(datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p'))
Date(year=2005, month=6, day=1, hour=12, minute='00', second='00')
string.format help: https://pyformat.info
"""
Date = namedtuple('Date', 'year month day hour minute second')
return Date(str(ct.year),
str(ct.month).zfill(2),
str(ct.day).zfill(2),
str((ct.hour - 1)).zfill(2),
str(m).zfill(2),
str(s).zfill(2))
date = normalize_date(ct) # Date(year='2018', month='04', day='08', hour='15', minute='00', second='00')
def download_link(date):
base_url = "https://dumps.wikimedia.org/other/pageviews/"
download_url = base_url + ("{}/{}/pageviews-{}-{}.gz"
.format(date.year,
date.year + date.month,
date.year + date.month + date.day,
date.hour + date.minute + date.second))
return download_url
ct = datetime.now() # get current time
for link in [download_link(normalize_date(ct, str(m).zfill(2), '00')) for m in range(0, 60)]:
print(link)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment