Created
April 10, 2016 01:34
-
-
Save harrisj/3d8b0158bc72dd34c36b996d8875790c to your computer and use it in GitHub Desktop.
My hackish Ruby script for hopping to a random NYT issue in the years 1851 - 1922 (ie, in the public domain)
This file contains hidden or 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 ruby | |
years = (1851..1922).to_a | |
months = (1..12).to_a | |
def max_day_for_month(month, year) | |
case month | |
when 1, 3, 5, 7, 8, 10, 12 | |
31 | |
when 9, 4, 6, 11 | |
30 | |
when 2 | |
(year % 4 == 0 && year % 100 != 0) ? 29 : 28 | |
end | |
end | |
year = years.sample | |
month = months.sample | |
day = (1..max_day_for_month(month, year)).to_a.sample | |
url = "http://timesmachine.nytimes.com/timesmachine/#{year}/#{ "%02d" % month }/#{ "%02d" % day }/issue.html" | |
`open #{url}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment