def fetch_earlier(self, comic, earliest):
number = int(earliest) - 1
+ irow = self.get_irow(comic, number)
+ if irow:
+ print "got irow: "
+ print irow
+ print "\ninserting first...\n"
+ self.insert_row_first(irow)
+ else:
+ print "No comic found at " + number
+
+ def get_irow(self, comic, number):
if number < 0:
return False
print "number is now: " + str(number) + "\n"
link = "http://www.sinfest.net/archive_page.php?comicID=" + str(number)
else:
return False
+
print "link: " + link + "\n"
try:
f = urllib2.urlopen(link)
if (hcode != 200):
return False
else:
- # Build db entry.
- # they look like: comic,id,link,url,filename,title
- # We already have comic, number/id and link
-
+ # Build db entry.
+ # they look like: comic,id,link,url,filename,title
+ # We already have comic, number/id and link
+
if comic == 'xkcd':
s = f.read()
f.close()
+ # This should be done with regex but...
splt = string.split(s, "<h3>Image URL (for hotlinking/embedding): ", 1)
splt2 = string.split(splt[1], "</h3>", 1)
url = splt2[0]
splt = string.split(splt[0], "<h1>", 1)
splt = string.split(splt[1], "</h1>", 1)
+
title = splt[0]
elif comic == 'sinfest':
splt = string.split(splt[1], '" border="0" />', 1)
title = splt[0]
splt2 = string.rsplit(url, "/", 1)
- filename = splt2[1]
+ filename = splt2[1]
irow = [comic,number,link,url,filename,title]
- print "got irow: "
- print irow
- print "\ninserting first...\n"
- self.insert_row_first(irow)
+ return irow
+ print "got irow: "
+ def fetch_latest_std(self, comic, latest):
- def fetch_latest_std(self, comic, latest):
-
- print "fetching new after " + str(comic) + " " + str(latest) + "\n"
- hcode = 200
- number = int(latest) + 1
- while hcode == 200:
- print "number is now: " + str(number) + "\n"
- if comic == 'xkcd':
- link = "http://xkcd.org/" + str(number) + "/"
- elif comic == 'sinfest':
- link = "http://www.sinfest.net/archive_page.php?comicID=" + str(number)
- else:
- break
- print "link: " + link + "\n"
- try:
- f = urllib2.urlopen(link)
- hcode = f.code
- except:
- hcode = 404
- print "got hcode = " + str(hcode) + "\n"
- if (hcode != 200):
- break
- else:
- # Build db entry.
- # they look like: comic,id,link,url,filename,title
- # We already have comic, number/id and link
-
- if comic == 'xkcd':
- s = f.read()
- f.close()
- splt = string.split(s, "<h3>Image URL (for hotlinking/embedding): ", 1)
- splt2 = string.split(splt[1], "</h3>", 1)
- url = splt2[0]
- splt = string.split(splt[0], "<h1>", 1)
- splt = string.split(splt[1], "</h1>", 1)
- title = splt[0]
-
- elif comic == 'sinfest':
- s = f.read()
- f.close()
- splt = string.split(s, 'height="107"', 1)
- splt = string.split(splt[1], '<img src="', 1)
- splt = string.split(splt[1], '" alt="', 1)
- url = splt[0]
- if len(url) < 49:
- print "Fake 404! Break break break!"
- break
- splt = string.split(splt[1], '" border="0" />', 1)
- title = splt[0]
-
- splt2 = string.rsplit(url, "/", 1)
- filename = splt2[1]
- irow = [comic,number,link,url,filename,title]
+ print "fetching new after " + str(comic) + " " + str(latest) + "\n"
+ number = int(latest) + 1
+ while True:
+ irow = self.get_irow(comic, number)
+ if irow:
print "got irow: "
print irow
print "\ninserting...\n"
-
self.insert_row(irow)
+ number += 1
+ else:
+ break
- number += 1
+# ------------
class ComicHomePlugin(hildondesktop.HomePluginItem):
def __init__(self):