moved babyblues, fixed
[comic-widget] / src / usr / lib / hildon-desktop / comicwidget.py
index c4c8228..03328d1 100644 (file)
@@ -18,13 +18,19 @@ socket.setdefaulttimeout(30)
 supports_alpha = False
 
 # LOGGING!
-# sys.stdout = open('/home/user/.comic-widget/output_log.txt', 'a')
-# sys.stderr = open('/home/user/.comic-widget/error_log.txt', 'a')
+if not os.path.exists("/home/user/.comic-widget/"):
+       print "path not found: /home/user/.comic-widget/"
+       try:
+               os.makedirs("/home/user/.comic-widget/")
+       except:
+               print "logging failed on mkdir"
+sys.stdout = open('/home/user/.comic-widget/output_log.txt', 'a', 0)
+sys.stderr = open('/home/user/.comic-widget/error_log.txt', 'a', 0)
 # print "Start logging!"
 
 # constants. dbfile is the location of the csv
 # comiccache is the location of the images
-APP_VERSION = "0.4.3"
+APP_VERSION = "0.4.4"
 
 basedbdir = "/opt/comic-widget/db/"
 imagedir = "/opt/comic-widget/images/"
@@ -40,7 +46,6 @@ comics = {
                "arlonjaniscomicscom":{"name":"Arlo and Janis","link":'http://comics.com/arlo&janis/',"start":"2010-02-01","dbfile":dbdir + "comicdb.arlonjanis.csv"},
                "bccomicscom":{"name":"B.C.","link":"http://comics.com/bc/","start":"2010-02-01","dbfile":dbdir + "comicdb.bc.csv"},
                "ballard_streetcomicscom":{"name":"Ballard Street","link":"http://comics.com/ballard_street/","start":"2010-02-01","dbfile":dbdir + "comicdb.ballardstreet.csv"},
-               "babyblues":{"name":"Baby Blues","link":"http://www.babyblues.com/","start":"01/19/2010","dbfile":dbdir + "comicdb.babyblues.csv"},
                "bencomicscom":{"name":"Ben","link":'http://comics.com/ben/',"start":"2010-02-01","dbfile":dbdir + "comicdb.ben.csv"},
                "bettycomicscom":{"name":"Betty","link":"http://comics.com/betty/","start":"2010-02-01","dbfile":dbdir + "comicdb.betty.csv"},
                "big_natecomicscom":{"name":"Big Nate","link":"http://comics.com/big_nate/","start":"2010-02-01","dbfile":dbdir + "comicdb.bignate.csv"},
@@ -141,6 +146,7 @@ comics = {
                "amazing_spidermanckdm":{"name":"The Amazing Spider-Man","link":'http://content.comicskingdom.net/Spiderman/',"start":"20100209","dbfile":dbdir + "comicdb.spiderman.csv"},
                "apartment_3-gckdm":{"name":"Apartment 3-G","link":'http://content.comicskingdom.net/Apartment_3-G/',"start":"20100209","dbfile":dbdir + "comicdb.partment3g.csv"},
                "arcticckdm":{"name":"Arctic Circle","link":'http://content.comicskingdom.net/Arctic/',"start":"20100209","dbfile":dbdir + "comicdb.arctic.csv"},
+               "baby_bluesckdm":{"name":"Baby Blues","link":"http://content.comicskingdom.net/Baby_Blues/","start":"20100319","dbfile":dbdir + "comicdb.babybluesckdm.csv"},
                "barney_googleckdm":{"name":"Barney Google and Snuffy Smith","link":'http://content.comicskingdom.net/Barney_Google/',"start":"20100209","dbfile":dbdir + "comicdb.barneygoogle.csv"},
                "beetle_baileyckdm":{"name":"Beetle Bailey","link":'http://content.comicskingdom.net/Beetle_Bailey/',"start":"20100209","dbfile":dbdir + "comicdb.beetlebailey.csv"},
                "better_halfckdm":{"name":"Better Half","link":'http://content.comicskingdom.net/Better_Half/',"start":"20100209","dbfile":dbdir + "comicdb.betterhalf.csv"},
@@ -201,6 +207,8 @@ comics = {
                "toddckdm":{"name":"Todd the Dinosaur","link":'http://content.comicskingdom.net/Todd/',"start":"20100209","dbfile":dbdir + "comicdb.todd.csv"},
                "zippy_the_pinheadckdm":{"name":"Zippy the Pinhead","link":'http://content.comicskingdom.net/Zippy_the_Pinhead/',"start":"20100209","dbfile":dbdir + "comicdb.zippythepinhead.csv"},
                "zitsckdm":{"name":"Zits","link":'http://content.comicskingdom.net/Zits/',"start":"20100209","dbfile":dbdir + "comicdb.zits.csv"},
+               "viivijawagnerhesari":{"name":"Viivi ja Wagner","link":"http://www.hs.fi/viivijawagner/","start":"1135255013425","dbfile":dbdir + "comicdb.viivijawagner.csv"},
+               "fingerporihesari":{"name":"Fingerpori","link":"http://www.hs.fi/fingerpori/","start":"1135255790645","dbfile":dbdir + "comicdb.fingerpori.csv"},
 
 
 
@@ -411,7 +419,7 @@ class ComicDb():
 # fetch earlier
        def fetch_earlier(self, comic, earliest):
                print "fetch before, " + comic + " earliest"
-               if comic == "cyanide" or comic == "wulff" or comic == "babyblues" or comic[-9:] == "comicscom":
+               if comic == "cyanide" or comic == "wulff" or comic == "babyblues" or comic[-9:] == "comicscom" or comic[-6:] == "hesari":
                        print "getting get_prev_id..."
                        comicid = self.get_prev_id(comic,earliest)
                        if not comicid:
@@ -445,14 +453,14 @@ class ComicDb():
                        print "\ninserting...\n"
                        self.insert_row_first([irow[0],irow[1],irow[2],irow[3],irow[4],irow[5]])
                else:
-                       print "No comic found at " + comicid
+                       print "No comic found at " + str(comicid)
 
 
 
 
 
        def fetch_newer(self, comic, newest):
-               if comic == "cyanide" or comic == "wulff" or comic == "babyblues" or comic[-9:] == "comicscom":
+               if comic == "cyanide" or comic == "wulff" or comic == "babyblues" or comic[-9:] == "comicscom" or comic[-6:] == "hesari":
                        comicid = self.get_next_id(comic,newest)
                        if not comicid:
                                print "already at last comic"
@@ -645,7 +653,39 @@ class ComicDb():
                                s = f.read()
                                f.close()
                                return self.parse_comics_com(comic, s, 'next')
-
+               elif comic[-6:] == "hesari":
+                       realcomic = string.split( comic, 'hesari', 1)
+                       linkname = realcomic[0]
+                       link = comics[comic]['link'] + str(number)
+                       print "link: " + link
+                       try:
+                               f = urllib2.urlopen(link)
+                               hcode = f.code
+                       except:
+                               hcode = 404
+                       print "got hcode = " + str(hcode) + "\n"
+                       if (hcode != 200):
+                               return False
+                       else:
+                               print "checking next HS issue..."
+                               s = f.read()
+                               f.close()
+                               # title:
+                               vw = string.split(s, '<div id=\"VW_container\">',1)
+                               vw2=string.split(vw[1], '<div class=\"next\"', 1)
+                               vw3=string.split(vw2[1], '</div>', 1)
+                               splt = string.split(vw3[0], 'Seuraava', 1)
+                               if len(splt) < 2:
+                                       print "no 'next' found"
+                                       return False
+                               else:
+                                       splt3=string.split(vw3[0], '<a href=\"http://www.hs.fi/' + linkname + '/', 1)
+                                       splt4=string.split(splt3[1], '\" class=\"vw\"', 1)
+                                       next = splt4[0]
+                                       print "got next: " + next
+                                       return next
+               else:
+                       return False
 
 
 
@@ -744,8 +784,40 @@ class ComicDb():
                                s = f.read()
                                f.close()
                                return self.parse_comics_com(comic, s, 'prev')
-
-
+               elif comic[-6:] == 'hesari':
+                       print "checking prev..."
+                       realcomic = string.split( comic, 'hesari', 1)
+                       linkname = realcomic[0]
+                       link = comics[comic]['link'] + str(number)
+                       print "link: " + link
+                       try:
+                               f = urllib2.urlopen(link)
+                               hcode = f.code
+                       except:
+                               hcode = 404
+                       print "got hcode = " + str(hcode) + "\n"
+                       if (hcode != 200):
+                               return False
+                       else:
+                               print "checking prev HS issue.."
+                               s = f.read()
+                               f.close()
+                               # title:
+                               vw = string.split(s, '<div id=\"VW_container\">',1)
+                               vw2=string.split(vw[1], '<div class=\"previous\"', 1)
+                               vw3=string.split(vw2[1], '</div>', 1)
+                               splt = string.split(vw3[0], 'Edellinen', 1)
+                               if len(splt) < 2:
+                                       print "no 'prev' found"
+                                       return False
+                               else:
+                                       splt3=string.split(vw3[0], '<a href=\"http://www.hs.fi/' + linkname + '/', 1)
+                                       splt4=string.split(splt3[1], '\" class=\"vw\"', 1)
+                                       next = splt4[0]
+                                       print "got prev: " + next
+                                       return next
+               else:
+                       return False
 
 
        def get_irow(self, comic, number):
@@ -772,6 +844,8 @@ class ComicDb():
                        link = "http://www.babyblues.com/archive/index.php?formname=getstrip&GoToDay=" + str(number)
                elif comic[-9:] == 'comicscom': 
                        link = comics[comic]['link'] + str(number) + "/"
+               elif comic[-6:] == 'hesari':    
+                       link = comics[comic]['link'] + str(number)
                elif comic[-4:] == 'ckdm':
                        splt = string.rsplit(comics[comic]['link'], "/", 2)
                        cname = splt[1]
@@ -789,12 +863,12 @@ class ComicDb():
                        return False
 
                print "link: " + link
-               try:
-                       f = urllib2.urlopen(link)
-                       hcode = f.code
-               except:
-                       hcode = 404
-               print "got hcode = " + str(hcode) + "\n"
+               #try:
+               f = urllib2.urlopen(link)
+               hcode = f.code
+               #except:
+               #       hcode = 404
+               print "got hcode = " + str(hcode) + "asdf\n"
                if (hcode != 200):
                        return False
                else:
@@ -944,7 +1018,24 @@ class ComicDb():
                                url = self.parse_comics_com(comic, f.read(), 'url') 
                                f.close()
                                title = number
-
+                       elif comic[-6:] == 'hesari':
+                               # HS images are usually type .gif
+                               s = f.read()
+                               f.close()
+                               splt = string.split(s, 'http://www.hs.fi/kuvat/iso_webkuva/', 1)
+                               #print "splitted"  + "\n"
+                               flnm = string.split(splt[1], "\" align=", 1)
+                               #print flnm[0]  + "\n" + "url: "
+                               url = 'http://www.hs.fi/kuvat/iso_webkuva/' + flnm[0]
+                               #print url
+                               splt3 = string.split(s, '<div id=\"VW_container\">',1)
+                               splt4 = string.split(splt3[1], '<p>', 1)
+                               splt5 = string.split(splt4[1], '</p>', 1)
+                               title = splt5[0]
+                               #print title
+                               filename = str(number) + ".gif"
+                               irow = [comic,number,link,url,filename,title]
+                               return irow
                        elif comic[-4:] == 'ckdm':
                                url = link
                                title = number[:4] + "-" + number[4:6] + "-" + number[6:8]
@@ -1315,11 +1406,22 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                height = int(self.sizes['height'])
                picwidth = width - 2
                maxheight = height - 48
-
+               retimg = gtk.Image()
+               if os.path.isfile(filename) == False:
+                       filename = "/opt/comic-widget/images/up0-48x48.png"
+                       pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
+                       parent_buf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pixbuf.get_has_alpha(), 8, width, maxheight)
+                       parent_buf.fill(0x00000000)
+                       tmpy = (maxheight / 2) - 24
+                       tmpx = (width / 2) - 24
+                       pixbuf.copy_area(0,0,48,48,parent_buf,int(tmpx),int(tmpy))
+                       retimg.set_from_pixbuf(parent_buf)
+                       print retimg.get_pixel_size()
+                       print "No image found, posting up arrow"
+                       return retimg
                pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
                parent_buf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pixbuf.get_has_alpha(), 8, width, maxheight)
                parent_buf.fill(0xffffffff)
-               retimg = gtk.Image()
                # get correct width/height
                new_height = 1
                new_width = picwidth
@@ -1496,7 +1598,7 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                dialog.set_name("Comic widget")
                dialog.set_version(APP_VERSION)
                dialog.set_copyright("Copyright 2010 Marcus Wikstrom")
-               dialog.set_authors(["Marcus Wikstrom <mece@ovi.com>\nLogo by Martin Wikstrom\n\nSpecial thanks to all the great python developers on t.m.o who share their code, and the helpful wizards on #maemo."])
+               dialog.set_authors(["Marcus Wikstrom <mece@ovi.com>\nAdditional code by Lari Tuononen\nLogo by Martin Wikstrom\n\nSpecial thanks to all the great python developers on t.m.o,\n and the helpful wizards on #maemo."])
                dialog.set_logo(gtk.gdk.pixbuf_new_from_file("/opt/comic-widget/images/icon2-64x64.png"))
                dialog.set_comments("Silly rabbit, tricks are for kids.")
                dialog.set_license("""This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License. <http://www.gnu.org/licenses/>.""")
@@ -1589,8 +1691,8 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
 
        def get_size_settings(self):
                # defaults = {'width':480,'height':230}
-               # options: w 798 700 600 500 480 400
-               # options: h 420 360 310 270 240 200
+               # options: w 798 - 400
+               # options: h 420 - 200
                print "checking to see if config file is available"
                if os.path.isfile(sizefile) == True:
                        print "found " + sizefile