X-Git-Url: http://git.maemo.org/git/?p=comic-widget;a=blobdiff_plain;f=src%2Fusr%2Flib%2Fhildon-desktop%2Fcomicwidget.py;h=ed655b82e7bda03c955cde8d589e5a84ca73c965;hp=984470e67eb55ad84a44f3f711925c685a0a9104;hb=4a22b7247e4e5512a1d6aec70b383b3664dc47b5;hpb=40d9e0fd70097f0eece19f0f1d9911956bdf0575
diff --git a/src/usr/lib/hildon-desktop/comicwidget.py b/src/usr/lib/hildon-desktop/comicwidget.py
index 984470e..ed655b8 100644
--- a/src/usr/lib/hildon-desktop/comicwidget.py
+++ b/src/usr/lib/hildon-desktop/comicwidget.py
@@ -4,28 +4,150 @@ import hildondesktop
import gtk
import csv
import urllib2
-import urllib
import string
import os
import osso
import cairo
import datetime
import shutil
+import sys
+import socket
+
+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')
+# print "Start logging!"
+
# constants. dbfile is the location of the csv
# comiccache is the location of the images
-APP_VERSION = "0.2.5"
+APP_VERSION = "0.4.1-1"
basedbdir = "/opt/comic-widget/db/"
imagedir = "/opt/comic-widget/images/"
dbdir = "/home/user/.comic-widget/"
+activecomics = dbdir + "activecomics.cfg"
comiccache = "/home/user/MyDocs/.comics/"
-comics = {"xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":dbdir + "comicdb.xkcd.csv"},
- "sinfest":{"name":"Sinfest","link":"http://sinfest.com/","start":3400,"dbfile":dbdir + "comicdb.sinfest.csv"},
+defaultcomics = ['xkcd','wulff','sinfest']
+comics = {
+ "9_chickweed_lanecomicscom":{"name":"9 Chickweed Lane","link":"http://comics.com/9_chickweed_lane/","start":"2010-02-01","dbfile":dbdir + "comicdb.9chickweedlane.csv"},
+ "agnescomicscom":{"name":"Agnes","link":"http://comics.com/agnes/","start":"2010-02-01","dbfile":dbdir + "comicdb.agnes.csv"},
+ "andy_cappcomicscom":{"name":"Andy Capp","link":"http://comics.com/andy_capp/","start":"2010-02-01","dbfile":dbdir + "comicdb.andycapp.csv"},
+ "alley_oopcomicscom":{"name":"Alley Oop","link":"http://comics.com/alley_oop/","start":"2010-02-01","dbfile":dbdir + "comicdb.alleyoop.csv"},
+ "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"},
+ "brevitycomicscom":{"name":"Brevity","link":"http://comics.com/brevity/","start":"2010-02-01","dbfile":dbdir + "comicdb.brevity.csv"},
+ "candorvillecomicscom":{"name":"Candorville","link":"http://comics.com/candorville/","start":"2010-02-01","dbfile":dbdir + "comicdb.candorville.csv"},
+ "cheap_thrillscomicscom":{"name":"Cheap Thrills","link":"http://comics.com/cheap_thrills/","start":"2010-02-01","dbfile":dbdir + "comicdb.cheapthrills.csv"},
+ "committedcomicscom":{"name":"Committed","link":"http://comics.com/committed/","start":"2010-02-01","dbfile":dbdir + "comicdb.committed.csv"},
+ "cownboycomicscom":{"name":"Cow and Boy","link":'http://comics.com/cow&boy/',"start":"2010-02-01","dbfile":dbdir + "comicdb.cownboy.csv"},
+ "cyanide":{"name":"Cyanide and Happiness","link":"http://explosm.com/","start":"1920","dbfile":dbdir + "comicdb.cyanide.csv"},
+ "daddyshomecomicscom":{"name":"Daddy's Home","link":"http://comics.com/daddys_home/","start":"2010-02-01","dbfile":dbdir + "comicdb.daddyshome.csv"},
+ "dilbert":{"name":"Dilbert","link":"http://dilbert.com/","start":"2010-01-01","dbfile":dbdir + "comicdb.dilbert.csv"},
+ "dog_eat_dougcomicscom":{"name":"Dog eat Doug","link":"http://comics.com/dog_eat_doug/","start":"2010-02-01","dbfile":dbdir + "comicdb.dogeatdoug.csv"},
+ "drabblecomicscom":{"name":"Drabble","link":"http://comics.com/drabble/","start":"2010-02-01","dbfile":dbdir + "comicdb.drabble.csv"},
+ "f_minuscomicscom":{"name":"F Minus","link":"http://comics.com/f_minus/","start":"2010-02-01","dbfile":dbdir + "comicdb.f_minus.csv"},
+ "family_treecomicscom":{"name":"Family Tree","link":"http://comics.com/family_tree/","start":"2010-02-01","dbfile":dbdir + "comicdb.familytree.csv"},
+ "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"},
+ "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"},
+ "frazzcomicscom":{"name":"Frazz","link":"http://comics.com/frazz/","start":"2010-02-01","dbfile":dbdir + "comicdb.frazz.csv"},
+ "free_rangecomicscom":{"name":"Free Range","link":'http://comics.com/free_range/',"start":"2010-02-01","dbfile":dbdir + "comicdb.freerange.csv"},
+ "geechcomicscom":{"name":"Geech","link":'http://comics.com/geech_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.geech.csv"},
+ "getfuzzycomicscom":{"name":"Get Fuzzy","link":"http://comics.com/get_fuzzy/","start":"2010-02-01","dbfile":dbdir + "comicdb.getfuzzy.csv"},
+ "girlsnsportscomicscom":{"name":"Girls and Sports","link":'http://comics.com/girls&sports/',"start":"2010-02-01","dbfile":dbdir + "comicdb.gitlsnsports.csv"},
+ "graffiticomicscom":{"name":"Graffiti","link":'http://comics.com/graffiti/',"start":"2010-02-01","dbfile":dbdir + "comicdb.graffiti.csv"},
+ "grand_avenuecomicscom":{"name":"Grand Avenue","link":'http://comics.com/grand_avenue/',"start":"2010-02-01","dbfile":dbdir + "comicdb.grandavenue.csv"},
+ "heathcliffcomicscom":{"name":"Heathcliff","link":'http://comics.com/heathcliff/',"start":"2010-02-01","dbfile":dbdir + "comicdb.heathcliff.csv"},
+ "herb_and_jamaalcomicscom":{"name":"Herb and Jamaal","link":'http://comics.com/herb_and_jamaal/',"start":"2010-02-01","dbfile":dbdir + "comicdb.herbandjamaal.csv"},
+ "hermancomicscom":{"name":"Herman","link":'http://comics.com/herman/',"start":"2010-02-01","dbfile":dbdir + "comicdb.herman.csv"},
+ "home_and_awaycomicscom":{"name":"Home and Away","link":'http://comics.com/home_and_away/',"start":"2010-02-01","dbfile":dbdir + "comicdb.homeandaway.csv"},
+ "its_all_about_youcomicscom":{"name":"It's All About You","link":'http://comics.com/its_all_about_you/',"start":"2010-02-01","dbfile":dbdir + "comicdb.itsallaboutyou.csv"},
+ "janes_worldcomicscom":{"name":"Jane's World","link":'http://comics.com/janes_world/',"start":"2010-02-01","dbfile":dbdir + "comicdb.janesworld.csv"},
+ "jump_startcomicscom":{"name":"Jump Start","link":'http://comics.com/jump_start/',"start":"2010-02-01","dbfile":dbdir + "comicdb.jumpstart.csv"},
+ "kit_n_carlylecomicscom":{"name":"Kit 'n' Carlyle","link":'http://comics.com/kit_n_carlyle/',"start":"2010-02-01","dbfile":dbdir + "comicdb.kitncarlyle.csv"},
+ "lil_abnercomicscom":{"name":"Li'l Abner","link":'http://comics.com/lil_abner_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.lilabner.csv"},
+ "liberty_meadowscomicscom":{"name":"Liberty Meadows","link":'http://comics.com/liberty_meadows/',"start":"2010-02-01","dbfile":dbdir + "comicdb.libertymeadows.csv"},
+ "little_dog_lostcomicscom":{"name":"Little Dog Lost","link":'http://comics.com/little_dog_lost/',"start":"2010-02-01","dbfile":dbdir + "comicdb.littledoglost.csv"},
+ "lolacomicscom":{"name":"Lola","link":'http://comics.com/lola/',"start":"2010-02-01","dbfile":dbdir + "comicdb.lola.csv"},
+ "luanncomicscom":{"name":"Luann","link":'http://comics.com/luann/',"start":"2010-02-01","dbfile":dbdir + "comicdb.luann.csv"},
+ "marmadukecomicscom":{"name":"Marmaduke","link":'http://comics.com/marmaduke/',"start":"2010-02-01","dbfile":dbdir + "comicdb.marmaduke.csv"},
+ "megcomicscom":{"name":"Meg","link":'http://comics.com/meg_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.meg.csv"},
+ "minimum_securitycomicscom":{"name":"Minimum Security","link":'http://comics.com/minimum_security/',"start":"2010-02-01","dbfile":dbdir + "comicdb.minimumsecurity.csv"},
+ "moderately_confusedcomicscom":{"name":"Moderately Confused","link":'http://comics.com/moderately_confused/',"start":"2010-02-01","dbfile":dbdir + "comicdb.moderatelyconfused.csv"},
+ "mommacomicscom":{"name":"Momma","link":'http://comics.com/momma/',"start":"2010-02-01","dbfile":dbdir + "comicdb.momma.csv"},
+ "motleycomicscom":{"name":"Motley","link":'http://comics.com/motley_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.motley.csv"},
+ "nancycomicscom":{"name":"Nancy","link":'http://comics.com/nancy/',"start":"2010-02-01","dbfile":dbdir + "comicdb.nancy.csv"},
+ "natural_selectioncomicscom":{"name":"Natural Selection","link":'http://comics.com/natural_selection/',"start":"2010-02-01","dbfile":dbdir + "comicdb.naturalselection.csv"},
+ "nest_headscomicscom":{"name":"Nest Heads","link":'http://comics.com/nest_heads/',"start":"2010-02-01","dbfile":dbdir + "comicdb.nestheads.csv"},
+ "off_the_markcomicscom":{"name":"Off the mark","link":"http://comics.com/off_the_mark/","start":"2010-02-01","dbfile":dbdir + "comicdb.offthemark.csv"},
+ "on_a_claire_daycomicscom":{"name":"On A Claire Day","link":'http://comics.com/on_a_claire_day/',"start":"2010-02-01","dbfile":dbdir + "comicdb.onaclaireday.csv"},
+ "one_big_happycomicscom":{"name":"One Big Happy","link":'http://comics.com/one_big_happy_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.onebighappy.csv"},
+ "over_the_hedgecomicscom":{"name":"Over the Hedge","link":'http://comics.com/over_the_hedge/',"start":"2010-02-01","dbfile":dbdir + "comicdb.overthehedge.csv"},
+ "pc_and_pixelcomicscom":{"name":"PC and Pixel","link":'http://comics.com/pc_and_pixel/',"start":"2010-02-01","dbfile":dbdir + "comicdb.pcandpixel.csv"},
+ "peanutscomicscom":{"name":"Peanuts","link":"http://comics.com/peanuts/","start":"2010-02-01","dbfile":dbdir + "comicdb.peanuts.csv"},
+ "pearls_before_swinecomicscom":{"name":"Pearls Before Swine","link":'http://comics.com/pearls_before_swine/',"start":"2010-02-01","dbfile":dbdir + "comicdb.pearlsbeforeswine.csv"},
"phd":{"name":"PHD Comics","link":"http://www.phdcomics.com/","start":1240,"dbfile":dbdir + "comicdb.phd.csv"},
- "dilbert":{"name":"Dilbert","link":"http://dilbert.com.com/","start":"2009-01-01","dbfile":dbdir + "comicdb.dilbert.csv"}}
+ "picklescomicscom":{"name":"Pickles","link":'http://comics.com/pickles/',"start":"2010-02-01","dbfile":dbdir + "comicdb.pickles.csv"},
+ "prickly_citycomicscom":{"name":"Prickly City","link":'http://comics.com/prickly_city/',"start":"2010-02-01","dbfile":dbdir + "comicdb.pricklycity.csv"},
+ "raising_duncancomicscom":{"name":"Raising Duncan","link":'http://comics.com/raising_duncan_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.raisingduncan.csv"},
+ "reality_checkcomicscom":{"name":"Reality Check","link":'http://comics.com/reality_check/',"start":"2010-02-01","dbfile":dbdir + "comicdb.realitycheck.csv"},
+ "rednrovercomicscom":{"name":"Red and Rover","link":'http://comics.com/red&rover/',"start":"2010-02-01","dbfile":dbdir + "comicdb.rednrover.csv"},
+ "rip_haywirecomicscom":{"name":"Rip Haywire","link":'http://comics.com/rip_haywire/',"start":"2010-02-01","dbfile":dbdir + "comicdb.riphaywire.csv"},
+ "ripleys_believe_it_or_notcomicscom":{"name":"Ripley's Believe it or not","link":'http://comics.com/ripleys_believe_it_or_not/',"start":"2010-02-01","dbfile":dbdir + "comicdb.ripleysbelieveitornot.csv"},
+ "rose_is_rosecomicscom":{"name":"Rose Is Rose","link":'http://comics.com/rose_is_rose/',"start":"2010-02-01","dbfile":dbdir + "comicdb.roseisrose.csv"},
+ "rubescomicscom":{"name":"Rubes","link":'http://comics.com/rubes/',"start":"2010-02-01","dbfile":dbdir + "comicdb.rubes.csv"},
+ "rudy_parkcomicscom":{"name":"Rudy Park","link":'http://comics.com/rudy_park/',"start":"2010-02-01","dbfile":dbdir + "comicdb.rudypark.csv"},
+ "scary_garycomicscom":{"name":"Scary Gary","link":'http://comics.com/scary_gary/',"start":"2010-02-01","dbfile":dbdir + "comicdb.scarygary.csv"},
+ "shirley_and_soncomicscom":{"name":"Shirley and Son","link":'http://comics.com/shirley_and_son_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.shirleyandson.csv"},
+ "sinfest":{"name":"Sinfest","link":"http://sinfest.com/","start":3400,"dbfile":dbdir + "comicdb.sinfest.csv"},
+ "soup_to_nutzcomicscom":{"name":"Soup to Nutz","link":'http://comics.com/soup_to_nutz/',"start":"2010-02-01","dbfile":dbdir + "comicdb.souptonutz.csv"},
+ "speed_bumpcomicscom":{"name":"Speed Bump","link":'http://comics.com/speed_bump/',"start":"2010-02-01","dbfile":dbdir + "comicdb.speedbump.csv"},
+ "spot_the_frogcomicscom":{"name":"Spot the Frog","link":'http://comics.com/spot_the_frog/',"start":"2010-02-01","dbfile":dbdir + "comicdb.spotthefrog.csv"},
+ "state_of_the_unioncomicscom":{"name":"State of the Union","link":'http://comics.com/state_of_the_union/',"start":"2010-02-01","dbfile":dbdir + "comicdb.stateoftheunion.csv"},
+ "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"},
+ "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"},
+ "working_dazecomicscom":{"name":"Working Daze","link":'http://comics.com/working_daze/',"start":"2010-02-01","dbfile":dbdir + "comicdb.workingdaze.csv"},
+ "working_it_outcomicscom":{"name":"Working It Out","link":'http://comics.com/working_it_out/',"start":"2010-02-01","dbfile":dbdir + "comicdb.workingitout.csv"},
+ "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"},
+
+
+
+ }
+defaults = {'width':480,'height':230}
+#defaults = {'width':480,'height':240}
+sizefile = "/home/user/.comic-widget/size.cfg"
+previous = False
+next = False
+
# handling of the comics
class ComicDb():
@@ -44,6 +166,8 @@ class ComicDb():
for row in dbr:
self.db.insert(0,row)
dbf.close()
+ if len(self.db) == 0:
+ self.refresh()
self.currentcomic = 0
@@ -73,6 +197,7 @@ class ComicDb():
dbf = open(self.dbfile, 'w')
dbf.write('comic,id,link,url,filename,title\n')
dbf.close()
+
if os.path.isfile(self.dbfile) == True:
dbf = open(self.dbfile, 'r')
return dbf
@@ -83,10 +208,21 @@ class ComicDb():
def get_comic(self):
print str(self.currentcomic)
if self.currentcomic < 0:
- self.refresh()
self.currentcomic = 0
+ if len(self.db) > 0:
+ fetchid = self.db[self.currentcomic]['id']
+ else:
+ fetchid = comics[self.comic]['start']
+ self.fetch_newer(self.comic, fetchid)
+ self.refresh()
if len(self.db) < (self.currentcomic + 1):
- self.currentcomic -= 1
+ print "Empty db"
+ self.currentcomic = len(self.db) - 1
+ if len(self.db) > 0:
+ fetchid = self.db[self.currentcomic]['id']
+ else:
+ fetchid = comics[self.comic]['start']
+ self.fetch_earlier(self.comic, fetchid)
self.refresh()
self.currentcomic = len(self.db) - 1
@@ -107,7 +243,20 @@ class ComicDb():
print "created dir"
except:
print "comic db creation failed on mkdir"
- urllib.urlretrieve(dbrow['url'], filename)
+ try:
+ f = open(filename, "wb")
+ print "writing to " + filename
+ req = urllib2.Request(dbrow['url'])
+ req.add_header('Referer', dbrow['link'])
+ tmpimg = urllib2.urlopen(req)
+ f.write(tmpimg.read())
+ tmpimg = None
+ f.close()
+
+# urllib.urlretrieve(dbrow['url'], filename)
+ except:
+ if os.path.isfile(filename):
+ os.remove(filename)
print "success\n"
return filename
@@ -146,21 +295,41 @@ class ComicDb():
dbf.close()
def refresh(self):
- if len(self.db) < 1:
- self.fetch_latest_std(self.comic, self.start)
- elif self.currentcomic == 0 or self.currentcomic < 0:
- self.fetch_latest_std(self.comic, self.db[0]['id'])
- elif self.currentcomic == (len(self.db) - 1):
- self.fetch_earlier(self.comic, self.db[self.currentcomic]['id'])
+ # if len(self.db) < 1:
+ # self.currentcomic = -1
+ # self.fetch_latest_std(self.comic, self.start)
+ # elif self.currentcomic == 0 or self.currentcomic < 0:
+ # self.fetch_latest_std(self.comic, self.db[0]['id'])
+ # elif self.currentcomic == (len(self.db) - 1):
+ # self.fetch_earlier(self.comic, self.db[self.currentcomic]['id'])
dbf = open(self.dbfile, 'r')
dbr = csv.DictReader(dbf)
self.db = []
for row in dbr:
self.db.insert(0,row)
dbf.close()
+ if len(self.db) == 0:
+ self.fetch_earlier(self.comic, self.start)
+ dbf = open(self.dbfile, 'r')
+ dbr = csv.DictReader(dbf)
+ self.db = []
+ for row in dbr:
+ self.db.insert(0,row)
+ dbf.close()
+
+# fetch earlier
def fetch_earlier(self, comic, earliest):
- if len(earliest) == 10:
+ 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)
+ if not comicid:
+ print "already at first comic"
+ return
+ print "got " + comicid + " as the one before current..."
+ elif len(str(earliest)) == 10:
# date id.
dt = string.split(earliest, "-")
d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
@@ -170,49 +339,314 @@ class ComicDb():
comicid = int(earliest) - 1
irow = self.get_irow(comic, comicid)
- if irow:
+ if irow and irow[0] == "skip":
+ print "problem with this one, fetching " + str(irow[2]) + " instead."
+ irow = self.get_irow(comic, irow[2])
+
+ if irow and len(irow) > 3:
print "got irow: "
print irow
- print "\ninserting first...\n"
- self.insert_row_first(irow)
+ 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
- def fetch_latest_std(self, comic, latest):
- print "fetching new after " + str(comic) + " " + str(latest)
- dateid = False
- if len(str(latest)) == 10:
+
+
+
+
+ def fetch_newer(self, comic, newest):
+ if comic == "cyanide" or comic == "wulff" or comic == "babyblues" or comic[-9:] == "comicscom":
+ comicid = self.get_next_id(comic,newest)
+ if not comicid:
+ print "already at last comic"
+ return
+ elif len(newest) == 10:
# date id.
- dateid = True
- dt = string.split(latest, "-")
+ dt = string.split(newest, "-")
d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
- newer = d + datetime.timedelta( 1 )
- comicid = newer.isoformat()
+ newest = d + datetime.timedelta( 1 )
+ comicid = newest.isoformat()
else:
- comicid = int(latest) + 1
+ comicid = int(newest) + 1
- lasturl = self.db[0]['url']
+ irow = self.get_irow(comic, comicid)
+ if irow and irow[0] == "skip":
+ print "problem with this one, fetching " + str(irow[1]) + " instead."
+ irow = self.get_irow(comic, irow[1])
+
+ if irow and len(irow) > 3:
+ print "got irow: "
+ print irow
+ print "\ninserting...\n"
+ self.insert_row([irow[0],irow[1],irow[2],irow[3],irow[4],irow[5]])
+ else:
+ print "No comic found at " + str(comicid)
+
+
+
+
+ def fetch_latest_std(self, comic, latest):
+ print "fetching new after " + str(comic) + " " + str(latest)
+ next = False
+ dateid = False
+ if comic == 'cyanide':
+ next = self.get_next_id(comic, latest)
+ if not next:
+ return
+ else:
+ comicid = next
+ else:
+ if len(str(latest)) == 10:
+ # date id.
+ dateid = True
+ dt = string.split(latest, "-")
+ d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
+ newer = d + datetime.timedelta( 1 )
+ comicid = newer.isoformat()
+ else:
+ comicid = int(latest) + 1
+
+ if len(self.db) > 0:
+ lasturl = self.db[0]['url']
+ else:
+ lasturl = "http"
while True:
irow = self.get_irow(comic, comicid)
if irow:
print "got irow: " + str(irow)
- if irow[3] == lasturl:
- print "Looping the same, break break break!"
- break
- lasturl = irow[3]
- print "inserting..."
- self.insert_row(irow)
+ if str(irow[0]) == 'skip':
+ print "skipping this one..."
+ next = int(irow[1])
+ else:
+ if irow[3] == lasturl:
+ print "Looping the same, break break break!"
+ break
+ lasturl = irow[3]
+ print "inserting..."
+ self.insert_row([irow[0],irow[1],irow[2],irow[3],irow[4],irow[5]])
+ if len(irow) > 6:
+ next = irow[6]
+ if not next:
+ break
if dateid:
dt = string.split(comicid, "-")
d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
newer = d + datetime.timedelta( 1 )
comicid = newer.isoformat()
+ elif next:
+ comicid = next
else:
comicid += 1
else:
break
+
+
+ def get_next_id(self, comic, number):
+ if comic == 'babyblues':
+ link = "http://www.babyblues.com/archive/index.php?formname=getstrip&GoToDay=" + 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 Babyblues date.."
+ s = f.read()
+ f.close()
+ # title:
+ splt = string.split(s, 'nextStripLink', 1)
+ if len(splt) < 2:
+ print "no 'prev' found"
+ return False
+ else:
+ next = splt[1][48:58]
+ print "got next: " + next
+
+ return next
+
+ if comic == 'cyanide':
+ link = "http://www.explosm.net/comics/" + 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 "Cyanide & Happiness is unreliable, so we need to track next and prev"
+ s = f.read()
+ f.close()
+ # title:
+ splt = string.split(s, 'Previous | Next >', 1)
+ if len(splt) < 2:
+ print "no 'next' found"
+ return False
+ else:
+ print "got next: " + splt[0]
+ return splt[0]
+ if comic == 'wulff':
+ link = "http://wulffmorgenthaler.com/default.aspx?id=" + 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:
+ s = f.read()
+ f.close()
+ # title:
+ splt = string.split(s, ' | < Previous', 1)
+ if len(splt) < 2 or len(splt[0]) > 5:
+ print "no 'next' found"
+ return False
+ else:
+ print "got previous: " + splt[0]
+ return splt[0]
+ elif comic == 'wulff':
+ link = "http://wulffmorgenthaler.com/default.aspx?id=" + 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:
+ s = f.read()
+ f.close()
+ # title:
+ splt = string.split(s, 'Image URL (for hotlinking/embedding): ", 1)
- splt2 = string.split(splt[1], "", 1)
- url = splt2[0]
- splt = string.split(splt[0], "", 1)
- splt = string.split(splt[1], "
", 1)
-
+ splt = string.split(s, 'png" title="', 1)
+ splt = string.split(splt[1], '" alt="', 1)
title = splt[0]
+ splt = string.split(splt[1], "Image URL (for hotlinking/embedding): ", 1)
+ splt = string.split(splt[1], "
", 1)
+ url = splt[0]
+
elif comic == 'sinfest':
s = f.read()
@@ -295,29 +737,165 @@ class ComicDb():
if len(url) < 49:
print "Fake 404! Break break break!"
return False
-
+
+ elif comic == 'cyanide':
+ s = f.read()
+ f.close()
+ # title:
+ splt = string.split(s, ' First | < ', 1)
+ prev = splt[0];
+ print "got prev: " + prev
+ splt = string.split(s, 'Previous | Next >', 1)
+ if len(splt[0]) > 10:
+ next = False
+ else:
+ next = splt[0]
+ print "got next: " + next
+
+ splt = string.split(s, '