import urllib, os, datetime, subprocess def yearsago(years, from_date=None): if from_date is None: from_date = datetime.datetime.now().date() try: return from_date.replace(year=from_date.year - years) except: # Must be 2/29! assert from_date.month == 2 and from_date.day == 29 # can be removed return from_date.replace(month=2, day=28, year=from_date.year-years) urlPre = 'http://chemistry.gravitywaves.com/logs/chatlog_' urlDate = '11_11_08' urlExt= '.log' today = datetime.datetime.now().date() startDate = yearsago(years=15) while (startDate!=today): urlDate = startDate.strftime('%m_%d_%y') startDate += datetime.timedelta(days=1) temp=''.join((urlPre,urlDate,urlExt)) print temp #urllib.urlretrieve(temp) subprocess.call(["wget", temp])