Ooops Sorry, no attachment. Ok... more probs with my GetGarf program... First I acidently and permanently deleted all versions and now I've improved it but it won't download new images.... Here's the code (attached... sorry :-( ) More Questions to come later. Thanks, Joe
#! /usr/bin/env python ############################################## # Created by Joseph Quigley # # This program is under the GNU GPL Licence # # Either version 2 or any higher version. # # Garfield and the Garfield trade mark are # # Copyrighted by Paws Inc. # ##############################################
# Import modules import time import urllib2 import os from Tkinter import * import Image import ImageTk import getpass class Data: # Define time and date todays_date = time.localtime(time.time()) dayNum = time.strftime("%d", todays_date) monthNum = time.strftime("%m", todays_date) yearNum = time.strftime("%y", todays_date) yearNumFull = time.strftime("%Y", todays_date) ocDay = dayNum ocMonth = monthNum ocYear = yearNum ocYearFull = yearNumFull # More file location junk stripName ="http://images.ucomics.com/comics/ga/%s/" % (yearNumFull) todayStrip = "ga%s%s%s.gif" % (yearNum, monthNum, dayNum) configFile = file("/home/%s/.getgarf/config" % (getpass.getuser()), 'r') location = configFile.readline() download = "" f = "" # Help stuff commands = """ get today -->\tDownload today's (%s/%s/%s) garfield. If it is already downloaed it will read \toff the hard drive cache. get other -->\tNot yet available h --> \tDisplay this help exit --> \tClose Program""" % (monthNum, dayNum, yearNum) help = """Config file: GetGarf is picky, the config file must have the exact location of the images and dirctories that GetGarf uses. On Linux the config file is in the user's home directory.""" def Connect(url): # Errors urllib2_URLError = """Temporary failure in name resolution. This means that you may not be online or the site is down. You may want to try again later.""" print "Connecting to server..." try: Data.f = urllib2.urlopen(url) except urllib2.URLError: print urllib2_URLError print "Connected." def Dsp_Image(pic): root = Tk() root.title("Garfield Comic Reader") app = Frame(root) app.grid() img = Image.open(pic) imgPrep = ImageTk.PhotoImage(img) imgShow = Label(app, image=imgPrep).grid() #imgDate = Label(app, text="Showing a %s/%s/%s strip" % (Data.monthNum, Data.dayNum, Data.yearNum)).grid() app.mainloop() def Save_Image(pic): print "Dowloading Image" pic_data = Data.geturl() pic_Data = Data.f.read() picture = file(pic, 'w') picture.write(pic_Data) picture.close() print "Done." # Enough defining lets get our hands dirty. def main(): while True: prompt = raw_input("Type 'h' (no quotes) for help and press Enter (Return).\nGetGarf> ") if prompt == "get today": try: Dsp_Image("%s/%s" % (Data.location, Data.todayStrip)) except IOError: Connect("%s%s" % (Data.stripName, Data.todayStrip)) Save_Image("%sga%s%s%s.gif" % (Data.location, Data.ocMonth, Data.ocDay, Data.ocYear)) print "Displaying Image.\n" elif prompt == "get old": oldComicDate = raw_input("Type the date in yymmdd format.\nNo /'s please (eg: 010309 for 2001, March 9th)\n> ") year = raw_input("Enter the year of the commic you'd like to view: ") try: Dsp_Image("%s/ga%s.gif" % (Data.location, oldComicDate)) except IOError: Connect("http://images.ucomics.com/comics/ga/%s/%s" % (year, oldComicDate)) Save_Image("%s/ga%s.gif" % (Data.location, oldComicDate)) print "Displaying Image.\n" Dsp_Image("%s/ga%s.gif" % (Data.location, oldComicDate)) elif ((prompt == 'h') or ('H' == prompt)): print "Here are the commands you can type:" print Data.commands print print Data.help elif prompt == "exit": raise SystemExit else: print Data.commands main()
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor