added Lari Tuononens scripts
[comic-widget] / src / usr / lib / hildon-desktop / comicwidget.py
index 5dd1fe6..303b620 100644 (file)
@@ -19,12 +19,12 @@ supports_alpha = False
 
 # LOGGING!
 # sys.stdout = open('/home/user/.comic-widget/output_log.txt', 'a', 0)
-sys.stderr = open('/home/user/.comic-widget/error_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/"
@@ -199,9 +199,10 @@ comics = {
                "tigerckdm":{"name":"Tiger","link":'http://content.comicskingdom.net/Tiger/',"start":"20100209","dbfile":dbdir + "comicdb.tiger.csv"},
                "tinas_grooveckdm":{"name":"Tina's Groove","link":'http://content.comicskingdom.net/Tinas_Groove/',"start":"20100209","dbfile":dbdir + "comicdb.tinasgroove.csv"},
                "toddckdm":{"name":"Todd the Dinosaur","link":'http://content.comicskingdom.net/Todd/',"start":"20100209","dbfile":dbdir + "comicdb.todd.csv"},
-               "viivijawagnermatinmaapallo":{"name":"Viivi ja Wagner","link":"http://matin.maapallo.org/site.pl/selain/?c=viivijawagner&i=","start":"2500","dbfile":dbdir + "comicdb.viivijawagner.csv"},\r
                "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"},
+               "calvinandhobbesmatinmaapallo":{"name":"Calvin and Hobbes","link":"http://matin.maapallo.org/site.pl/selain/?c=lassijaleevi&i=","start":"2008","dbfile":dbdir + "comicdb.calvinandhobbes.csv"},\r
+               "viivijawagnermatinmaapallo":{"name":"Viivi ja Wagner","link":"http://matin.maapallo.org/site.pl/selain/?c=viivijawagner&i=","start":"2600","dbfile":dbdir + "comicdb.viivijawagner.csv"},\r
 
 
 
@@ -412,7 +413,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[-13:] == "matinmaapallo":
                        print "getting get_prev_id..."
                        comicid = self.get_prev_id(comic,earliest)
                        if not comicid:
@@ -446,14 +447,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[-13:] == "matinmaapallo":
                        comicid = self.get_next_id(comic,newest)
                        if not comicid:
                                print "already at last comic"
@@ -775,7 +776,7 @@ class ComicDb():
                                return self.parse_comics_com(comic, s, 'prev')
                elif comic[-13:] == 'matinmaapallo':\r
                        print "checking matin maapallo..."\r
-                        prevint = int( number ) - 1\r
+                       prevint = int( number ) - 1\r
                        if ( prevint  == 0 ):\r
                                print "cannot go previous"\r
                                return False\r
@@ -811,6 +812,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[-13:] == 'matinmaapallo':    
+                       link = comics[comic]['link'] + str(number)
                elif comic[-4:] == 'ckdm':
                        splt = string.rsplit(comics[comic]['link'], "/", 2)
                        cname = splt[1]
@@ -983,6 +986,23 @@ class ComicDb():
                                url = self.parse_comics_com(comic, f.read(), 'url') 
                                f.close()
                                title = number
+                       elif comic[-13:] == 'matinmaapallo':
+                               # matin maapallo links is type .gif
+                               s = f.read()
+                               f.close()
+                               splt = string.split(s, 'http://matin.maapallo.org/kuvatuuppari/', 1)
+                               #print "splitted"  + "\n"
+                               flnm = string.split(splt[1], ".gif", 1)
+                               #print flnm[0]  + "\n" + "url: "
+                               url = 'http://matin.maapallo.org/kuvatuuppari/' + flnm[0] + '.gif'
+                               #print url
+                               splt3 = string.split(s, '<h4>', 1)
+                               splt4 = string.split(splt3[1], '</h4>', 1)
+                               title = splt4[0]
+                               print title
+                               filename = str(number) + ".gif"
+                               irow = [comic,number,link,url,filename,title]
+                               return irow
 
                        elif comic[-4:] == 'ckdm':
                                url = link
@@ -1362,10 +1382,14 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                        parent_buf.fill(0x00000000)
                        tmpy = (maxheight / 2) - 24
                        tmpx = (width / 2) - 24
-                       pixbuf.copy_area(0,0,picwidth,scaled_buf.get_height(),parent_buf,int(tmpx),int(tmpy))
-                       return 
+                       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)
                # get correct width/height
                new_height = 1
                new_width = picwidth
@@ -1542,7 +1566,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/>.""")