Skip to content

Instantly share code, notes, and snippets.

@vagmi
Created November 18, 2008 09:25
Show Gist options
  • Save vagmi/26087 to your computer and use it in GitHub Desktop.
Save vagmi/26087 to your computer and use it in GitHub Desktop.
some bug fixes
import urllib2
import datetime
import os.path
from BeautifulSoup import BeautifulSoup
dilbert_dir = 'c:\\work\\toons\\dilbert\\'
year=2007
start_date=datetime.date(year,1,1)
one_day = datetime.timedelta(days=1)
current_date = start_date
base_url = r'http://www.dilbert.com/fast/'
while(current_date.year==year and current_date <= datetime.date.today()):
dtfmt=current_date.strftime('%Y-%m-%d')
contents=urllib2.urlopen(base_url + dtfmt + '/').read()
soup=BeautifulSoup(contents)
img_loc=soup.findAll('img')[-1]['src']
print 'downloading ', img_loc, ' as ', dtfmt, '.gif'
img=urllib2.urlopen('http://www.dilbert.com/' + img_loc).read()
f=open(os.path.join(dilbert_dir,dtfmt+'.gif'),'wb')
f.write(img)
f.close()
current_date= current_date + one_day
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment