Skip to content

Instantly share code, notes, and snippets.

@ariefbayu
Created March 12, 2012 07:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariefbayu/2020633 to your computer and use it in GitHub Desktop.
Save ariefbayu/2020633 to your computer and use it in GitHub Desktop.
Google Doodle Downloader by @pengelana
#!/usr/bin/env python
import os
import urllib2
import datetime
import time
try:
import json
except:
import simplejson as json
def main():
t = datetime.datetime.now()
delta = datetime.timedelta(days=1)
path = 'google' + os.path.sep + 'doodles'
url = "http://www.google.com/doodles/json/%s/%s"
yy = 1998
mm = 8
y, m = 0, 0
doodle = []
while(1):
y = t.year
m = t.month
t = datetime.datetime(y, m, 1) - delta
if y == yy and m < mm: break
doodle.append(url % (y, m))
if not os.path.exists(path):
os.makedirs(path)
for d in doodle:
html = urllib2.urlopen(d).read()
doodle_ = json.loads(html)
for dd in doodle_:
run_date = time.localtime(dd['run_date'])
ext = dd['url'].split('.')[-1]
base_dir = path + os.path.sep + str(run_date[0]) +\
os.path.sep + str(run_date[1])
if not os.path.exists(base_dir):
os.makedirs(base_dir)
print "%s - %s" % (time.strftime('%Y-%m-%d', run_date), dd['title'])
name_ = time.strftime('%d-%b-%Y', run_date) +\
"_" + dd['name'] + '_' + dd['id'] + '.' + ext
image_ = urllib2.urlopen('http:' + dd['url']).read()
file(base_dir + os.path.sep + name_, 'wb').write(image_)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment