X-Git-Url: http://git.maemo.org/git/?p=comic-widget;a=blobdiff_plain;f=src%2Fusr%2Flib%2Fhildon-desktop%2Fcomicwidget.py;h=5dd1fe65e91007397c30222ae6613941915d6379;hp=ed655b82e7bda03c955cde8d589e5a84ca73c965;hb=1e95ad9439ae6395d900e5a029fa7351f5c1ea57;hpb=4a22b7247e4e5512a1d6aec70b383b3664dc47b5 diff --git a/src/usr/lib/hildon-desktop/comicwidget.py b/src/usr/lib/hildon-desktop/comicwidget.py index ed655b8..5dd1fe6 100644 --- a/src/usr/lib/hildon-desktop/comicwidget.py +++ b/src/usr/lib/hildon-desktop/comicwidget.py @@ -18,13 +18,13 @@ 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') +# 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.1-1" +APP_VERSION = "0.4.3" basedbdir = "/opt/comic-widget/db/" imagedir = "/opt/comic-widget/images/" @@ -59,7 +59,7 @@ comics = { "farcuscomicscom":{"name":"Farcus","link":'http://comics.com/farcus/',"start":"2010-02-01","dbfile":dbdir + "comicdb.farcus.csv"}, "fat_catscomicscom":{"name":"Fat Cats","link":'http://comics.com/fat_cats_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.fatcats.csv"}, "ferdnandcomicscom":{"name":"Ferd'nand","link":'http://comics.com/ferdnand/',"start":"2010-02-01","dbfile":dbdir + "comicdb.ferdnand.csv"}, - "flight_deckcomicscom":{"name":"Flight_Deck","link":'http://comics.com/flight_deck/',"start":"2010-02-01","dbfile":dbdir + "comicdb.flightdeck.csv"}, + "flight_deckcomicscom":{"name":"Flight Deck","link":'http://comics.com/flight_deck/',"start":"2010-02-01","dbfile":dbdir + "comicdb.flightdeck.csv"}, "flonfriendscomicscom":{"name":"Flo and Friends","link":'http://comics.com/flo&friends/',"start":"2010-02-01","dbfile":dbdir + "comicdb.flonfriends.csv"}, "fort_knoxcomicscom":{"name":"Fort Knox","link":'http://comics.com/fort_knox/',"start":"2010-02-01","dbfile":dbdir + "comicdb.fortknox.csv"}, "franknernestcomicscom":{"name":"Frank and Ernest","link":'http://comics.com/frank&ernest/',"start":"2010-02-01","dbfile":dbdir + "comicdb.franknernest.csv"}, @@ -120,16 +120,16 @@ comics = { "strange_brewcomicscom":{"name":"Strange Brew","link":'http://comics.com/strange_brew/',"start":"2010-02-01","dbfile":dbdir + "comicdb.strangebrew.csv"}, "tarzancomicscom":{"name":"Tarzan","link":'http://comics.com/tarzan_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.tarzan.csv"}, "thats_lifecomicscom":{"name":"That's Life","link":'http://comics.com/thats_life/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thatslife.csv"}, - "the_barncomicscom":{"name":"The Barn","link":'http://comics.com/the_barn/',"start":"2010-02-01","dbfile":dbdir + "comicdb.the_barn.csv"}, - "the_born_losercomicscom":{"name":"The Born Loser","link":'http://comics.com/the_born_loser/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thebornloser.csv"}, - "the_bucketscomicscom":{"name":"The Buckets","link":'http://comics.com/the_buckets/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thebuckets.csv"}, - "the_dinette_setcomicscom":{"name":"The Dinette Set","link":'http://comics.com/the_dinette_set/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thedinetteset.csv"}, - "the_grizzwellscomicscom":{"name":"The Grizzwells","link":'http://comics.com/the_grizzwells/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thegrizzwells.csv"}, - "the_humble_stumblecomicscom":{"name":"The Humble Stumble","link":'http://comics.com/the_humble_stumble/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thehumblestumble.csv"}, - "the_knight_lifecomicscom":{"name":"The Knight Life","link":'http://comics.com/the_knight_life/',"start":"2010-02-01","dbfile":dbdir + "comicdb.theknightlife.csv"}, - "the_meaning_of_lilacomicscom":{"name":"The Meaning of Lila","link":'http://comics.com/the_meaning_of_lila/',"start":"2010-02-01","dbfile":dbdir + "comicdb.themeaningoflila.csv"}, - "the_other_coastcomicscom":{"name":"The Other Coast","link":'http://comics.com/the_other_coast/',"start":"2010-02-01","dbfile":dbdir + "comicdb.theothercoast.csv"}, - "the_sunshine_clubcomicscom":{"name":"the Sunshine Club","link":'http://comics.com/the_sunshine_club/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thesunshineclub.csv"}, + "barncomicscom":{"name":"The Barn","link":'http://comics.com/the_barn/',"start":"2010-02-01","dbfile":dbdir + "comicdb.the_barn.csv"}, + "born_losercomicscom":{"name":"The Born Loser","link":'http://comics.com/the_born_loser/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thebornloser.csv"}, + "bucketscomicscom":{"name":"The Buckets","link":'http://comics.com/the_buckets/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thebuckets.csv"}, + "dinette_setcomicscom":{"name":"The Dinette Set","link":'http://comics.com/the_dinette_set/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thedinetteset.csv"}, + "grizzwellscomicscom":{"name":"The Grizzwells","link":'http://comics.com/the_grizzwells/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thegrizzwells.csv"}, + "humble_stumblecomicscom":{"name":"The Humble Stumble","link":'http://comics.com/the_humble_stumble/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thehumblestumble.csv"}, + "knight_lifecomicscom":{"name":"The Knight Life","link":'http://comics.com/the_knight_life/',"start":"2010-02-01","dbfile":dbdir + "comicdb.theknightlife.csv"}, + "meaning_of_lilacomicscom":{"name":"The Meaning of Lila","link":'http://comics.com/the_meaning_of_lila/',"start":"2010-02-01","dbfile":dbdir + "comicdb.themeaningoflila.csv"}, + "other_coastcomicscom":{"name":"The Other Coast","link":'http://comics.com/the_other_coast/',"start":"2010-02-01","dbfile":dbdir + "comicdb.theothercoast.csv"}, + "sunshine_clubcomicscom":{"name":"The Sunshine Club","link":'http://comics.com/the_sunshine_club/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thesunshineclub.csv"}, "unstrange_phenomenacomicscom":{"name":"Unstrange Phenomena","link":'http://comics.com/unstrange_phenomena/',"start":"2010-02-01","dbfile":dbdir + "comicdb.unstrangephenomena.csv"}, "watch_your_headcomicscom":{"name":"Watch Your Head","link":'http://comics.com/watch_your_head/',"start":"2010-02-01","dbfile":dbdir + "comicdb.watchyourhead.csv"}, "wizard_of_idcomicscom":{"name":"Wizard of Id","link":'http://comics.com/wizard_of_id/',"start":"2010-02-01","dbfile":dbdir + "comicdb.wizardofid.csv"}, @@ -138,6 +138,70 @@ comics = { "wulff":{"name":"Wulffmorgenthaler","link":"http://wulffmorgenthaler.com/","start":"edd3411b-96ca-4d93-bd5f-0cf1deb67c8a","dbfile":dbdir + "comicdb.wulff.csv"}, "xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":dbdir + "comicdb.xkcd.csv"}, "zack_hillcomicscom":{"name":"Zack Hill","link":'http://comics.com/zack_hill/',"start":"2010-02-01","dbfile":dbdir + "comicdb.zackhill.csv"}, + "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"}, + "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"}, + "between_friendsckdm":{"name":"Between Friends","link":'http://content.comicskingdom.net/Between_Friends/',"start":"20100209","dbfile":dbdir + "comicdb.betweenfriends.csv"}, + "bizarrockdm":{"name":"Bizarro","link":'http://content.comicskingdom.net/Bizarro/',"start":"20100209","dbfile":dbdir + "comicdb.bizarro.csv"}, + "blondieckdm":{"name":"Blondie","link":'http://content.comicskingdom.net/Blondie/',"start":"20100209","dbfile":dbdir + "comicdb.blondie.csv"}, + "edisonckdm":{"name":"Edison Lee","link":'http://content.comicskingdom.net/Edison/',"start":"20100209","dbfile":dbdir + "comicdb.edison.csv"}, + "bucklesckdm":{"name":"Buckles","link":'http://content.comicskingdom.net/Buckles/',"start":"20100209","dbfile":dbdir + "comicdb.buckles.csv"}, + "crankshaftckdm":{"name":"Crankshaft","link":'http://content.comicskingdom.net/Crankshaft/',"start":"20100209","dbfile":dbdir + "comicdb.crankshaft.csv"}, + "crockckdm":{"name":"Crock","link":'http://content.comicskingdom.net/Crock/',"start":"20100209","dbfile":dbdir + "comicdb.crock.csv"}, + "curtisckdm":{"name":"Curtis","link":'http://content.comicskingdom.net/Curtis/',"start":"20100209","dbfile":dbdir + "comicdb.curtis.csv"}, + "deflockedckdm":{"name":"DeFlocked","link":'http://content.comicskingdom.net/Deflocked/',"start":"20100209","dbfile":dbdir + "comicdb.deflocked.csv"}, + "dennis_the_menaceckdm":{"name":"Dennis The Menace","link":'http://content.comicskingdom.net/Dennis_The_Menace/',"start":"20100209","dbfile":dbdir + "comicdb.dennisthemenace.csv"}, + "dustinckdm":{"name":"Dustin","link":'http://content.comicskingdom.net/Dustin/',"start":"20100209","dbfile":dbdir + "comicdb.dustin.csv"}, + "edge_cityckdm":{"name":"Edge City","link":'http://content.comicskingdom.net/Edge_City/',"start":"20100209","dbfile":dbdir + "comicdb.edgecity.csv"}, + "family_circusckdm":{"name":"Family Circus","link":'http://content.comicskingdom.net/Family_Circus/',"start":"20100209","dbfile":dbdir + "comicdb.familycircus.csv"}, + "flashckdm":{"name":"Flash Gordon","link":'http://content.comicskingdom.net/Flash/',"start":"20100209","dbfile":dbdir + "comicdb.flash.csv"}, + "funky_winkerbeanckdm":{"name":"Funky Winkerbean","link":'http://content.comicskingdom.net/Funky_Winkerbean/',"start":"20100209","dbfile":dbdir + "comicdb.funkywinkerbean.csv"}, + "grin_and_bear_itckdm":{"name":"Grin and Bear It","link":'http://content.comicskingdom.net/Grin_and_Bear_It/',"start":"20100209","dbfile":dbdir + "comicdb.frinandbearit.csv"}, + "hagar_the_horribleckdm":{"name":"Hagar The Horrible","link":'http://content.comicskingdom.net/Hagar_The_Horrible/',"start":"20100209","dbfile":dbdir + "comicdb.hagarthehorrible.csv"}, + "hazelckdm":{"name":"Hazel","link":'http://content.comicskingdom.net/Hazel/',"start":"20100209","dbfile":dbdir + "comicdb.hazel.csv"}, + "heavensckdm":{"name":"Heaven's Love Thrift Shop","link":'http://content.comicskingdom.net/Heavens/',"start":"20100209","dbfile":dbdir + "comicdb.heavens.csv"}, + "henryckdm":{"name":"Henry","link":'http://content.comicskingdom.net/Henry/',"start":"20100209","dbfile":dbdir + "comicdb.henry.csv"}, + "hi_and_loisckdm":{"name":"Hi and Lois","link":'http://content.comicskingdom.net/Hi_and_Lois/',"start":"20100209","dbfile":dbdir + "comicdb.hiandlois.csv"}, + "judge_parkerckdm":{"name":"Judge Parker","link":'http://content.comicskingdom.net/Judge_Parker/',"start":"20100209","dbfile":dbdir + "comicdb.judgeparker.csv"}, + "katzenjammer_kidsckdm":{"name":"Katzenjammer Kids","link":'http://content.comicskingdom.net/Katzenjammer_Kids/',"start":"20100209","dbfile":dbdir + "comicdb.katzenjammerkids.csv"}, + "lockhornsckdm":{"name":"Lockhorns","link":'http://content.comicskingdom.net/Lockhorns/',"start":"20100209","dbfile":dbdir + "comicdb.lockhorns.csv"}, + "mallard_fillmoreckdm":{"name":"Mallard Fillmore","link":'http://content.comicskingdom.net/Mallard_Fillmore/',"start":"20100209","dbfile":dbdir + "comicdb.mallardfillmore.csv"}, + "mandrakeckdm":{"name":"Mandrake","link":'http://content.comicskingdom.net/Mandrake/',"start":"20100209","dbfile":dbdir + "comicdb.mandrake.csv"}, + "mark_trailckdm":{"name":"Mark Trail","link":'http://content.comicskingdom.net/Mark_Trail/',"start":"20100209","dbfile":dbdir + "comicdb.marktrail.csv"}, + "marvinckdm":{"name":"Marvin","link":'http://content.comicskingdom.net/Marvin/',"start":"20100209","dbfile":dbdir + "comicdb.marvin.csv"}, + "mary_worthckdm":{"name":"Mary Worth","link":'http://content.comicskingdom.net/Mary_Worth/',"start":"20100209","dbfile":dbdir + "comicdb.maryworth.csv"}, + "mooseckdm":{"name":"Moose and Molly","link":'http://content.comicskingdom.net/Moose/',"start":"20100209","dbfile":dbdir + "comicdb.moose.csv"}, + "mgooseckdm":{"name":"Mother Goose and Grimm","link":'http://content.comicskingdom.net/Mgoose/',"start":"20100209","dbfile":dbdir + "comicdb.mgoose.csv"}, + "muttsckdm":{"name":"Mutts","link":'http://content.comicskingdom.net/Mutts/',"start":"20100209","dbfile":dbdir + "comicdb.mutts.csv"}, + "my_cageckdm":{"name":"My Cage","link":'http://content.comicskingdom.net/My_Cage/',"start":"20100209","dbfile":dbdir + "comicdb.mycage.csv"}, + "ollieckdm":{"name":"Ollie and Quentin","link":'http://content.comicskingdom.net/Ollie/',"start":"20100209","dbfile":dbdir + "comicdb.ollie.csv"}, + "on_the_fast_trackckdm":{"name":"On The Fastrack","link":'http://content.comicskingdom.net/Fast_Track/',"start":"20100209","dbfile":dbdir + "comicdb.fastrack.csv"}, + "pajamackdm":{"name":"Pajama Diaries","link":'http://content.comicskingdom.net/Pajama/',"start":"20100209","dbfile":dbdir + "comicdb.pajama.csv"}, + "pardon_my_planetckdm":{"name":"Pardon My Planet","link":'http://content.comicskingdom.net/Pardon_My_Planet/',"start":"20100209","dbfile":dbdir + "comicdb.pardonmyplanet.csv"}, + "phantomckdm":{"name":"The Phantom","link":'http://content.comicskingdom.net/Phantom/',"start":"20100209","dbfile":dbdir + "comicdb.phantom.csv"}, + "piranhackdm":{"name":"the Piranha Club","link":'http://content.comicskingdom.net/Piranha/',"start":"20100209","dbfile":dbdir + "comicdb.piranha.csv"}, + "popeyeckdm":{"name":"Popeye","link":'http://content.comicskingdom.net/Popeye/',"start":"20100209","dbfile":dbdir + "comicdb.popeye.csv"}, + "prince_valiantckdm":{"name":"Prince Valiant","link":'http://content.comicskingdom.net/Prince_Valiant/',"start":"20100209","dbfile":dbdir + "comicdb.prince_valiant.csv"}, + "prosnconsckdm":{"name":"Pros and Cons","link":'http://content.comicskingdom.net/Lawyer/',"start":"20100209","dbfile":dbdir + "comicdb.prosncons.csv"}, + "retailckdm":{"name":"Retail","link":'http://content.comicskingdom.net/Retail/',"start":"20100209","dbfile":dbdir + "comicdb.retail.csv"}, + "rex_morganckdm":{"name":"Rex Morgan","link":'http://content.comicskingdom.net/Rex_Morgan/',"start":"20100209","dbfile":dbdir + "comicdb.rexmorgan.csv"}, + "rhymes_with_orangeckdm":{"name":"Rhymes with Orange","link":'http://content.comicskingdom.net/Rhymes_with_Orange/',"start":"20100209","dbfile":dbdir + "comicdb.rhymeswithorange.csv"}, + "safe_havensckdm":{"name":"Safe Havens","link":'http://content.comicskingdom.net/Safe_Havens/',"start":"20100209","dbfile":dbdir + "comicdb.safehavens.csv"}, + "sallyforthckdm":{"name":"Sally Forth","link":'http://content.comicskingdom.net/Sally_Forth/',"start":"20100209","dbfile":dbdir + "comicdb.sallyforth.csv"}, + "samckdm":{"name":"Sam and Silo","link":'http://content.comicskingdom.net/Sam/',"start":"20100209","dbfile":dbdir + "comicdb.sam.csv"}, + "shermans_lagoonckdm":{"name":"Sherman's Lagoon","link":'http://content.comicskingdom.net/Shermans_Lagoon/',"start":"20100209","dbfile":dbdir + "comicdb.shermanslagoon.csv"}, + "shoeckdm":{"name":"Shoe","link":'http://content.comicskingdom.net/Shoe/',"start":"20100209","dbfile":dbdir + "comicdb.shoe.csv"}, + "six_chixckdm":{"name":"Six Chix","link":'http://content.comicskingdom.net/6Chix/',"start":"20100209","dbfile":dbdir + "comicdb.6chix.csv"}, + "slylockckdm":{"name":"Slylock Fox","link":'http://content.comicskingdom.net/Slylock/',"start":"20100209","dbfile":dbdir + "comicdb.slylock.csv"}, + "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"}, + "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"}, @@ -205,8 +269,32 @@ class ComicDb(): print "comic db creation failed after copy" + def get_stored(self): + try: + idf = open(self.dbfile + ".last", 'r') + retval = idf.read() + print "got stored index :" + str(retval) + idf.close() + return int(retval) + except: + return 0 + + + def store_last(self, sid = 0): + try: + idf = open(self.dbfile + ".last", 'w') + if sid > 0: + idf.write(str(sid)) + else: + idf.write(str(self.currentcomic)) + idf.close() + return True + except: + return False + + def get_comic(self): - print str(self.currentcomic) + # print str(self.currentcomic) if self.currentcomic < 0: self.currentcomic = 0 if len(self.db) > 0: @@ -216,11 +304,11 @@ class ComicDb(): self.fetch_newer(self.comic, fetchid) self.refresh() if len(self.db) < (self.currentcomic + 1): - print "Empty db" self.currentcomic = len(self.db) - 1 if len(self.db) > 0: fetchid = self.db[self.currentcomic]['id'] else: + print "Empty db" fetchid = comics[self.comic]['start'] self.fetch_earlier(self.comic, fetchid) self.refresh() @@ -279,6 +367,9 @@ class ComicDb(): dbw = csv.writer(dbf) dbw.writerow(irow) dbf.close() + stored = self.get_stored() + if stored > 0: + self.store_last(stored + 1) def insert_row_first(self, irow): dbf = open(self.dbfile, 'w') @@ -321,7 +412,6 @@ class ComicDb(): # fetch earlier def fetch_earlier(self, comic, earliest): print "fetch before, " + comic + " earliest" - print comic[-9:] if comic == "cyanide" or comic == "wulff" or comic == "babyblues" or comic[-9:] == "comicscom": print "getting get_prev_id..." comicid = self.get_prev_id(comic,earliest) @@ -335,6 +425,13 @@ class ComicDb(): d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2])) earlier = d - datetime.timedelta( 1 ) comicid = earlier.isoformat() + elif comic[-4:] == 'ckdm': + # comics kingdom. Easiest...? + d = datetime.date(int(earliest[:4]),int(earliest[4:6]),int(earliest[6:8])) + earlier = d - datetime.timedelta( 1 ) + comicid = str(earlier.strftime("%Y%m%d")) + + else: comicid = int(earliest) - 1 @@ -367,6 +464,11 @@ class ComicDb(): d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2])) newest = d + datetime.timedelta( 1 ) comicid = newest.isoformat() + elif comic[-4:] == 'ckdm': + # comics kingdom. Easiest...? + d = datetime.date(int(newest[:4]),int(newest[4:6]),int(newest[6:8])) + earlier = d + datetime.timedelta( 1 ) + comicid = str(earlier.strftime("%Y%m%d")) else: comicid = int(newest) + 1 @@ -544,7 +646,35 @@ class ComicDb(): s = f.read() f.close() return self.parse_comics_com(comic, s, 'next') - + elif comic[-13:] == "matinmaapallo": + realcomic = string.split( comic, 'matinmaapallo', 1) + linkname = realcomic[0] + link = "http://matin.maapallo.org/site.pl/selain/?c=" + linkname + "&i=" + str(number) + print "link: " + link + try: + f = urllib2.urlopen(link) + hcode = f.code + except: + hcode = 404 + print "got hcode = " + str(hcode) + "\n" + print "I am now here" + if (hcode != 200): + return False + else: + print "checking next matin maapallo issue.." + s = f.read() + f.close() + # title: + splt = string.split(s, 'seuraava', 1) + if len(splt) < 2: + print "no 'prev' found" + return False + else: + next = str( int(number) + 1 ) + print "got next: " + next + return next + else: + return False @@ -643,8 +773,18 @@ class ComicDb(): s = f.read() f.close() return self.parse_comics_com(comic, s, 'prev') - - + elif comic[-13:] == 'matinmaapallo': + print "checking matin maapallo..." + prevint = int( number ) - 1 + if ( prevint == 0 ): + print "cannot go previous" + return False + else: + print "got number: " + number + print "got previous: " + str(prevint) + return str(prevint) + else: + return False def get_irow(self, comic, number): @@ -671,6 +811,19 @@ 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[-4:] == 'ckdm': + splt = string.rsplit(comics[comic]['link'], "/", 2) + cname = splt[1] + if len(cname) == len(comic[:-4]): + link = comics[comic]['link'] + cname + "." + str(number) + "_small.gif" + else: + print "Weird link. Break break break!" + return False + d = datetime.date(int(number[:4]),int(number[4:6]),int(number[6:8])) + today = datetime.date.today() + if d > today: + print "Fetching the future! Break break break!" + return False else: return False @@ -831,6 +984,9 @@ class ComicDb(): f.close() title = number + elif comic[-4:] == 'ckdm': + url = link + title = number[:4] + "-" + number[4:6] + "-" + number[6:8] splt2 = string.rsplit(url, "/", 1) filename = splt2[1] try: @@ -875,6 +1031,11 @@ class ComicDb(): + + + + + # ------------UI class ComicHomePlugin(hildondesktop.HomePluginItem): @@ -961,9 +1122,11 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): self.e_goweb.add(self.label) self.e_goweb.set_events(gtk.gdk.BUTTON_RELEASE_MASK) - self.e_goweb.connect("button-release-event", self.view_comic) + self.e_goweb.connect("button-release-event", self.view_comic_web) self.e_open.add(self.comic_image) + self.e_open.set_events(gtk.gdk.BUTTON_PRESS_MASK) + self.e_open.connect("button-press-event", self.view_comic) # self.e_switch.add(self.switch) self.e_switch.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY) @@ -1013,7 +1176,7 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): # **************** Cairo draw functions *************** - def realize(self, widget): + def do_realize(self): global supports_alpha # To check if the display supports alpha channels, get the colormap @@ -1029,8 +1192,7 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): # Now we have a colormap appropriate for the screen, use it self.set_colormap(colormap) - - return False + hildondesktop.HomePluginItem.do_realize(self) def do_expose_event(widget, event): cr = widget.window.cairo_create() @@ -1050,7 +1212,7 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): cr.set_source_rgb (0.0, 0.0, 0.0) cr.fill_preserve() - return False + hildondesktop.HomePluginItem.do_expose_event(widget,event) # Function that draws a button preloaded in the images dictionary. def draw(self, target, postfix): @@ -1117,8 +1279,16 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): self.e_goweb.show_all() elif func == 'switch': + # Check if store needed.. + if not self.db.currentcomic == 0: + print "Storing location " + str(self.db.currentcomic) + if self.db.store_last(): + print "stored successfully" + else: + print "store failed" + self.active_comics = self.get_active_comics() - print "closing log" + # print "closing log" #sys.stdout.close() #sys.stdout = sys.__stdout__ #sys.stderr.close() @@ -1159,12 +1329,20 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): self.draw(widget, "0") # no fancy cairo stuff here. simply launches url in browser. - def view_comic(self, widget, event): + def view_comic_web(self, widget, event): if not event.type == gtk.gdk.BUTTON_RELEASE: return False link = self.db.get_link() self.osso_rpc.rpc_run_with_defaults("osso_browser", "open_new_window", (link,)) + # simply launches image in browser. + def view_comic(self, widget, event): + if not event.type == gtk.gdk._2BUTTON_PRESS: + return False + #link = self.db.get_link() + link = 'file:///home/user/MyDocs/.comics/' + self.db.comic + '/' + self.db.db[self.db.currentcomic]['filename'] + self.osso_rpc.rpc_run_with_defaults("osso_browser", "open_new_window", (link,)) + # this function modifies the image to fit the widget and then returns it. @@ -1176,11 +1354,18 @@ 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,picwidth,scaled_buf.get_height(),parent_buf,int(tmpx),int(tmpy)) + return 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 @@ -1188,12 +1373,14 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): scaled_buf = pixbuf.scale_simple(new_width,new_height,gtk.gdk.INTERP_BILINEAR) print "scaled height: " + str(scaled_buf.get_height()) if scaled_buf.get_height() > maxheight: + self.scrollable = True if scaled_buf.get_height() - (vpos + maxheight) < 0: vpos = scaled_buf.get_height() - maxheight scaled_buf.copy_area(0,vpos,picwidth,maxheight,parent_buf,1,0) # parent_buf.composite(scaled_buf, 0, 0, 478, maxheight, 0, 0, 478, maxheight, gtk.gdk.INTERP_BILINEAR, 0) self.imgvpos = vpos else: + self.scrollable = False tmpy = maxheight - scaled_buf.get_height() if tmpy > 0: tmpy = tmpy / 2 @@ -1275,6 +1462,20 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): #if not, write defaults + def goto_comic(self, index): + self.db.currentcomic = index + self.e_open.remove(self.comic_image) + self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos) + self.e_open.add(self.comic_image) + self.e_open.show_all() + self.e_goweb.remove(self.label) + titl = str(self.db.db[self.db.currentcomic]['title']) + if len(titl) > 22: + titl = titl[:19] + "..." + self.label.set_markup(self.get_markup()) + self.e_goweb.add(self.label) + self.e_goweb.show_all() + # ************************* OPTION DIALOGS ******************************** def show_options(self, widget): @@ -1291,12 +1492,32 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): comics_button.set_alignment(0,0,0,0) comics_button.connect("clicked", self.show_comics) + navfirst_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) + navfirst_button.set_text("Go to earliest", "Jump to the oldest cached comic") + navfirst_button.set_alignment(0,0,0,0) + navfirst_button.connect("clicked", self.show_nav, "oldest") + + navlast_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) + navlast_button.set_text("Go to latest", "Jump to the newest cached comic") + navlast_button.set_alignment(0,0,0,0) + navlast_button.connect("clicked", self.show_nav, "newest") + + navstored_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) + navstored_button.set_text("Go to stored comic", "Jump to where you were before you switched comics") + navstored_button.set_alignment(0,0,0,0) + navstored_button.connect("clicked", self.show_nav, "stored") + # size_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) # size_button.set_text("Change size", "Change the size of the widget") # size_button.set_alignment(0,0,0,0) # size_button.connect("clicked", self.show_size) + + print "adding buttons to dialog, starting with comics" + dialog.vbox.pack_start(navstored_button, True, True, 0) + dialog.vbox.pack_start(navfirst_button, True, True, 0) + dialog.vbox.pack_start(navlast_button, True, True, 0) dialog.vbox.pack_start(comics_button, True, True, 0) print "adding about button" dialog.vbox.pack_start(about_button, True, True, 0) @@ -1306,6 +1527,14 @@ class ComicHomePlugin(hildondesktop.HomePluginItem): dialog.run() dialog.destroy() + def show_nav(self, widget, goto): + if goto == "stored": + print "look for stored file" + self.goto_comic(self.db.get_stored()) + elif goto == "newest": + self.goto_comic(0) + elif goto == "oldest": + self.goto_comic(len(self.db.db) - 1) def show_about(self, widget): print "in about dialog" dialog = gtk.AboutDialog()