Last active
December 11, 2015 09:48
-
-
Save blech/4582676 to your computer and use it in GitHub Desktop.
A rough percentage of snowy photos in London
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 | |
import simplejson | |
import urllib | |
api_url = 'http://api.flickr.com/services/rest/' | |
api_method = 'flickr.photos.search' | |
api_key = '6cbbb899ee09051e575a63f57e954a5a' | |
results = {} | |
def get_count(min_taken_date, max_taken_date, text): | |
url_query = {'method': api_method, 'api_key': api_key, 'min_taken_date': min_taken_date, | |
'max_taken_date': max_taken_date, 'text': text, 'format': 'json', | |
'nojsoncallback': 1} | |
url = api_url + '?' + urllib.urlencode(url_query) | |
print "fetching %s" % url | |
response = urllib.urlopen(url) | |
document = simplejson.load(response) | |
count = document['photos']['total'] | |
print " returning count %s for text %s" % (count, text) | |
return int(count) | |
for year in range(2001, 2013): | |
next_year = year+1 | |
print "Handling year %s/%s" % (year, next_year) | |
min_taken_date = "%s-09-01 00:00:00" % year | |
max_taken_date = "%s-09-01 00:00:00" % next_year | |
snow = get_count(min_taken_date, max_taken_date, 'snow london -ontario') | |
total = get_count(min_taken_date, max_taken_date, 'london -ontario') | |
percent = float(snow)*100/total | |
results[year] = {'snow': snow, 'total': total, 'percent': percent} | |
for year in results: | |
print "%s\t%s\t%s\t%4f" % (year, | |
results[year]['snow'], | |
results[year]['total'], | |
results[year]['percent']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment