diff --git a/recipes/go_comics.recipe b/recipes/go_comics.recipe index 1c71c72659..6d384b95e6 100644 --- a/recipes/go_comics.recipe +++ b/recipes/go_comics.recipe @@ -3,16 +3,21 @@ __copyright__ = 'Copyright 2010 Starson17' ''' www.gocomics.com ''' +import shutil, os +from calibre.constants import iswindows from calibre.web.feeds.news import BasicNewsRecipe +from calibre.ptempfile import PersistentTemporaryDirectory +from calibre.utils.filenames import ascii_filename class GoComics(BasicNewsRecipe): title = 'Go Comics' - __author__ = 'Starson17' + __author__ = 'Kovid Goyal' __version__ = '1.06' __date__ = '07 June 2011' description = u'200+ Comics - Customize for more days/comics: Defaults to 1 day, 25 comics - 20 general, 5 editorial.' category = 'news, comics' + encoding = 'utf-8' language = 'en' no_stylesheets = True remove_javascript = True @@ -25,11 +30,6 @@ class GoComics(BasicNewsRecipe): # Please do not overload their servers by selecting all comics and 1000 # strips from each! - keep_only_tags = [ - dict(name='h1'), - dict(name='div', id=lambda x: x and x.startswith('mutable_')), - ] - def get_browser(self): br = BasicNewsRecipe.get_browser(self) br.addheaders = [('Referer', 'http://www.gocomics.com/')] @@ -37,6 +37,7 @@ class GoComics(BasicNewsRecipe): def parse_index(self): feeds = [] + self.gocomics_dir = PersistentTemporaryDirectory('_gocomics') for i, (title, url) in enumerate([ # {{{ # (u"The Academia Waltz",u"http://www.gocomics.com/academiawaltz"), # (u"Adam@Home",u"http://www.gocomics.com/adamathome"), @@ -537,15 +538,36 @@ class GoComics(BasicNewsRecipe): # (u"9 Chickweed Lane",u"http://www.gocomics.com/9chickweedlane"), ]): # }}} self.log('Working on: ', title, url) - articles = self.make_links(url) + articles = self.make_links(title, url) if articles: feeds.append((title, articles)) if self.test and i > 0: break return feeds - def make_links(self, url): - title = 'Temp' + def cleanup(self): + try: + shutil.rmtree(self.gocomics_dir) + except EnvironmentError: + pass + + def parse_comic_page(self, content): + img = content.find('img') + if img is None: + raise StopIteration() + img['srcset'] = '' + date = content.find('date') + return {'h1':content.find('h1'), 'date':self.tag_to_string(date), 'img':str(img)} + + def render_comic_page(self, data, num, title): + fname = ascii_filename('%03d_%s' % (num, title)).replace(' ', '_') + path = os.path.join(self.gocomics_dir, fname) + html = '
{h1}