Ok, new version (sorry to bug you).
This time I've edited the program so that you can only download todays (it won't work for any other date). Now I can connect to the server but it sticks on "Downloading image!"

Thanks for your prevoius help.
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
import sys
from Tkinter import *
import Image
import ImageTk
import getpass


class Data:
    # Define time and date
    todays_date = time.localtime(time.time())
    todayDay = time.strftime("%d", todays_date)
    todayMonth = time.strftime("%m", todays_date)
    todayYear = time.strftime("%y", todays_date)
    todayYearFull = time.strftime("%Y", todays_date)
    getDate = None
    month = None
    day = None
    yearFull = None
    year = None
    
    # More file location junk
    stripName ="http://images.ucomics.com/comics/ga/2005"# % (yearFull)
    todayStrip = "ga051009.gif"#ga%s%s%s.gif" % (todayYear, todayMonth, 
todayDay)
    otherStrip = None   
    download = None
    f = None
    VERSION = '0.9.3'

try:
    if sys.argv[1] == "--version":
        print """\nGacor %s
A Garfield Comic Downloader and reader.

    Copyright (C) 2005 Joseph Quigley

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
USA\n""" % Data.VERSION
    raise SystemExit

except IndexError:
    print "\n" * 100

user = getpass.getuser()
name = 'gacor'

if os.name == 'posix':
    imgDir = '/home/%s/.gacor/' % user
elif os.name == 'nt':
    if os.path.exists('C:\Documents and Settings'):
        imgDir = "C:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('D:\Documents and Settings'):
        imgDir = "D:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('E:\Documents and Settings'):
        imgDir = "E:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('F:\Documents and Settings'):
        imgDir = "F:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('G:\Documents and Settings'):
        imgDir = "G:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('H:\Documents and Settings'):
        imgDir = "H:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('I:\Documents and Settings'):
        imgDir = "I:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('J:\Documents and Settings'):
        imgDir = "J:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('K:\Documents and Settings'):
        imgDir = "K:\\Documents and Settings\\%s\\.gacor\\" % user
else:
    setImgDir = raw_input("Please specify your Documents and Settings 
Drive\n(eg: C:\\ not C)\n> ")
    imgDir = "%sDocuments and Settings\\%s\\.gacor\\" % user

if not os.path.exists(imgDir):
    os.mkdir(imgDir)

def Connect():
    print "Connecting to server..."
    try:
        Data.f = urllib2.urlopen("%s/%s" % (Data.stripName, Data.todayStrip))
    except  urllib2.URLError:
        print """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.\n\n This could also mean that you have entered 
a bad date in gettoher."""
        print "\n\nProgram will quit in 3 seconds."
        time.sleep(3)
        raise SystemExit
    print "Connected."

def Dsp_Image(pic):
    root = Tk()
    root.title("GaCoR (Garfield Comic Reader)")
    app = Frame(root)
    app.grid()
    img = Image.open(pic)
    imgPrep = ImageTk.PhotoImage(img)
    imgShow = Label(app, image=imgPrep).grid()
    info = Label(app, text="Displaying a Garfield for %s\%s\%s." % (Data.month, 
Data.day, Data.year)).grid()
    app.mainloop()


def getImg(pic):
    print "Dowloading Image"
    Data.f.geturl()
    pict_Data = Data.f.read()
    pict = file("%s" % (pic), 'w')
    pict.write(pict_Data)
    pict.close()
    print "Finished Download"

def ShowImg(pic):
    Dsp_Image("%s%s" % (imgDir, pic))

def comicDate():
    while True:
        print "\nEnter comic date in mmddyyyy format (eg: 09122002 "
        Data.getDate = list(raw_input("> "))
        if len(Data.getDate) > 8:
            print "Too many numbers! But I'll let this go."
        try:
            Data.month = Data.getDate[0] + Data.getDate[1]
        except IndexError:
            print "You didn't fill in all 2 digits in for the month!\n"
            continue
        try:
            Data.day = Data.getDate[2] + Data.getDate[3]
        except IndexError:
            print "You didn't fill in all 2 digits in for the day!\n"
            continue
        try:
            Data.yearFull = Data.getDate[4] + Data.getDate[5] + Data.getDate[6] 
+ Data.getDate[7]
        except IndexError:
            print "You didn't fill in all 4 digits in for the year!\n"
            continue
        Data.year = Data.getDate[6] + Data.getDate[7]
        break
def help():
    print """-- Help --

Commands:
    gettoday -- get today's strip
    getother -- get some other date's strip
    license  -- view the GNU General Public License (GPL)
    quit     -- Quit Program

If you find any bugs (most likely crashes) please report them to:
    [EMAIL PROTECTED]

Current version of software:
    %s

Gacor %s
A Garfield Comic Downloader and reader.

    Copyright (C) 2005 Joseph Quigley

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

  Garfield (tm) and the Garfield (tm) trade mark are
  Copyrighted by Paws Inc.""" % (Data.VERSION, Data.VERSION)

def license():
    print "\n" * 10
    while True:
        try:
            f = file("%slicense.txt" % imgDir, 'r')
        except IOError:
            print "The license file can not be found. You may download it 
from:\n\
\thttp://www.gnu.org/licenses/gpl.txt";
        print "Press enter to view more or the Ctrl C keys to go back to the 
main menu."
        text = f.readlines()
        length = len(text)
        line = 0
        while True:
            if line == length:
                break
            else:
                print text[line],
                try:
                    raw_input(),
                except KeyboardInterrupt:
                    break
                line = line + 1
        break

while True:
    try:
        m_m = raw_input("\n\nType 'h' for help\nMain Menu> ")
    except KeyboardInterrupt:
        raise SystemExit
    except TypeError:
        raise SystemExit
    if m_m == 'h':
        help()
    elif m_m == 'license':
        license()
    elif m_m == 'quit':
        raise SystemExit
    elif m_m == 'gettoday':
        Data.yearFull = Data.todayYearFull
        Data.year = Data.todayYear
        Data.month = Data.todayMonth
        Data.day = Data.todayDay
        print Data.yearFull, Data.year, Data.month, Data.day
        try:
            f = file("%s%s" % (imgDir, Data.todayStrip), 'r')
        except IOError:
            Connect()
            getImg(Data.todayStrip)
        ShowImg(Data.todayStrip)
        f.close()
    elif m_m == "getother":
        comicDate()
        Data.otherStrip = "ga%s%s%s.gif" % (Data.year, Data.month, Data.day)
        try:
            Data.f = file("%s%s" % (imgDir, Data.otherStrip), 'r')
        except IOError:
            Connect()
            getImg(Data.otherStrip)
        ShowImg(Data.otherStrip)
        Data.f.close()
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to