#!/bin/env python #http://images.ucomics.com/comics/ga/1978/ga780619.gif """ download Garfield comic from http://images.ucomics.com/ inspired by igoogle wadget from http://www.listen-project.de/ """ import os import getopt from time import localtime def DL_day(year, month, day, save_dir): """ the comic gif saved in http://images.ucomics.com/ """ # get file name if type(year) == type(1980): year = str(year) month = str(month) day = str(day) if len(year) == 2: if year < '78': year = '20' + year else: year = '19' + year if len(month) == 1: month = '0' + month if len(day) == 1: day = '0' + day gif_prefix = 'http://images.ucomics.com/comics/ga/' gif_address = gif_prefix + '/' + year + '/ga' + year[2:4]+month+day + '.gif' # get save directory if not os.path.exists(save_dir): os.mkdir(save_dir) os.chdir(save_dir) # subfolder for this year if not os.path.exists(year): os.mkdir(year) os.chdir(year) success_download = os.system('wget -nv -c -t 3 '+ gif_address) def DL_today(save_dir): today = localtime() year = today[0] month = today[1] day = today[2] DL_day(year, month, day, save_dir) def DL_month(year, month, save_dir): """ download all day comic pictures of this month """ from calendar import monthrange (first_weekday, last_month_day) = monthrange(year, month) for day in range(1, last_month_day+1): DL_day(year, month, day, save_dir) def DL_year(year, save_dir): today = localtime() if year > today[0] or year < 1978: print 'error: year must between 1978 and ' + str(today[0]) from sys import exit exit(1) if today[0] == year: # if last year how_many_month = today[1] for month in range (1, how_many_month): DL_month(year, month, save_dir) # last month for day in range(1, today[2]+1): DL_day(year, how_many_month, day, save_dir) else: if year == 1978: # first year for day in range(19, 30): # fist month DL_day(year, 6, day, save_dir) for month in range(7, 13): DL_month(year, month, save_dir) else: #other year for month in range (1, 12+1): DL_month(year, month, save_dir) if __name__ == "__main__": save_dir = '/home/lwl/downloads/Garfield/' # download today only DL_today(save_dir) # # uncomment below 2 lines to download all # for year in range(1978, 2007): # DL_year(year, save_dir) # # examples # DL_day(2000, 5, 13, save_dir) # DL_month(2000, 3, save_dir) # DL_year(2000, save_dir)