Created
October 19, 2011 15:19
-
-
Save Jeffrey903/1298600 to your computer and use it in GitHub Desktop.
Download all of the Steve Jobs remembrances on Apple's website
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/python | |
| # | |
| # Download all of the Steve Jobs remembrances on Apple's website | |
| # Will output to standard out | |
| # | |
| # Usage: python steve_jobs_remembrances.py > steve_jobs_remembrances.mdown | |
| # to save to a file | |
| # | |
| # At the time of writing this script, there were 5000 messages totaling ~1.5MB | |
| # | |
| # Thanks for everything Steve | |
| import json | |
| import urllib2 | |
| import sys | |
| import codecs | |
| sys.stdout = codecs.getwriter('utf-8')(sys.stdout) | |
| mainUrl = 'http://www.apple.com/stevejobs/messages/main.json' | |
| messageBaseUrl = 'http://www.apple.com/stevejobs/messages/' | |
| mainResponse = urllib2.urlopen(mainUrl) | |
| mainJson = json.loads(mainResponse.read()) | |
| for i in range(int(mainJson['totalMessages'])): | |
| messageUrl = messageBaseUrl + str(i) + '.json' | |
| messageResponse = urllib2.urlopen(messageUrl) | |
| unicodeJson = messageResponse.read().decode('utf-8') | |
| messageJson = json.loads(unicodeJson) | |
| print messageJson['header'] + '\n' + ('-' * len(messageJson['header'])) + '\n' | |
| print messageJson['mainText'] + '\n' | |
| if len(messageJson['location']) > 0: | |
| print '*' + messageJson['author'] + ' ' + messageJson['location'] + '*' + '\n' | |
| else: | |
| print '*' + messageJson['author'] + '*' + '\n' | |
| print '* * *\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment