From ba693e77a41e5797e35b48edf0d55a84cf070b3c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Jan 2010 13:22:35 -0700 Subject: [PATCH 1/3] New recipe for The Week magazine by Darko Miletic --- Changelog.yaml | 3 ++ .../images/news/the_week_magazine_free.png | Bin 0 -> 301 bytes .../recipes/the_week_magazine_free.recipe | 49 ++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 resources/images/news/the_week_magazine_free.png create mode 100644 resources/recipes/the_week_magazine_free.recipe diff --git a/Changelog.yaml b/Changelog.yaml index ab3140b2b1..6602651092 100644 --- a/Changelog.yaml +++ b/Changelog.yaml @@ -122,6 +122,9 @@ - title: Editor and Publisher author: XanthanGum + - title: The Week (free) + author: Darko Miletic + improved recipes: - Physics Today - Wall Street Journal diff --git a/resources/images/news/the_week_magazine_free.png b/resources/images/news/the_week_magazine_free.png new file mode 100644 index 0000000000000000000000000000000000000000..a7058ce2a27f23e287597887130117fb23bd9b5f GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^HbAV)0VEi%%Z5(?Qk-Q4j_E)eEWzOBpkM&x)Oxx& zhIkx*d)b?>!GMD$;9dR8!oZ7(v)sDXe5Gz&5t;W*IgOk7q()3dvCMCmbo-|S>CJl{@xVfq;7ib`m>2g&AM&hPM>n%nZ)Oa{x7D-(*G3v zP3HM^YJSAO+*jI%3T4Vd^|-|EN$GbnAIzR`N$lG4cA!I4OI#yLQW8s2t&)pUffR$0 zfuVt}fuXLEQHY_jm63s!v6-%cxs`!|Lj87g6b-rgDVb@NC>ji{j7)%fAR4B>*Ovoo OVDNPHb6Mw<&;$UE)Me5D literal 0 HcmV?d00001 diff --git a/resources/recipes/the_week_magazine_free.recipe b/resources/recipes/the_week_magazine_free.recipe new file mode 100644 index 0000000000..1bac4133e7 --- /dev/null +++ b/resources/recipes/the_week_magazine_free.recipe @@ -0,0 +1,49 @@ + +__license__ = 'GPL v3' +__copyright__ = '2010, Darko Miletic ' +''' +www.theweek.com +''' + +from calibre.web.feeds.news import BasicNewsRecipe + +class TheWeekFree(BasicNewsRecipe): + title = 'The Week Magazine - Free content' + __author__ = 'Darko Miletic' + description = "The best of the US and international media. Daily coverage of commentary and analysis of the day's events, as well as arts, entertainment, people and gossip, and political cartoons." + publisher = 'The Week Publications, Inc.' + category = 'news, politics, USA' + oldest_article = 7 + max_articles_per_feed = 100 + no_stylesheets = True + encoding = 'utf-8' + use_embedded_content = False + language = 'en' + + conversion_options = { + 'comment' : description + , 'tags' : category + , 'publisher' : publisher + , 'language' : language + } + + keep_only_tags = [ + dict(name=['h1','h2']) + , dict(name='div', attrs={'class':'basefont'}) + , dict(name='div', attrs={'id':'slideshowLoader'}) + ] + + remove_tags = [ + dict(name='div', attrs={'id':['digg_dugg','articleRight','dateHeader']}) + ,dict(name=['object','embed','iframe']) + ] + + + feeds = [ + (u'News & Opinions' , u'http://www.theweek.com/section/index/news_opinion.rss') + ,(u'Arts & Leisure' , u'http://www.theweek.com/section/index/arts_leisure.rss') + ,(u'Business' , u'http://www.theweek.com/section/index/business.rss' ) + ,(u'Cartoon & Short takes' , u'http://www.theweek.com/section/index/cartoons_wit.rss') + ] + + From 8e675576744cf4f24f69b2f83849b9107ccdc597 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Jan 2010 13:29:44 -0700 Subject: [PATCH 2/3] ... --- src/calibre/library/catalog.py | 49 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index 188f29c72b..cc10fa981a 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -6,7 +6,7 @@ from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, from calibre.customize import CatalogPlugin from calibre.ptempfile import PersistentTemporaryDirectory from calibre.customize.conversion import OptionRecommendation, DummyReporter - +from calibre import filesystem_encoding FIELDS = ['all', 'author_sort', 'authors', 'comments', 'cover', 'formats', 'id', 'isbn', 'pubdate', 'publisher', 'rating', @@ -377,7 +377,10 @@ class EPUB_MOBI(CatalogPlugin): self.text = ''.join(result) else: - number = int(self.number) + try: + number = int(self.number) + except: + return if number > 1000000: self.text = "%d out of range" % number @@ -2453,26 +2456,28 @@ class EPUB_MOBI(CatalogPlugin): def generateThumbnail(self, title, image_dir, thumb_file): import calibre.utils.PythonMagickWand as pw - try: - img = pw.NewMagickWand() - if img < 0: - raise RuntimeError('generate_thumbnail(): Cannot create wand') - # Read the cover - if not pw.MagickReadImage(img, title['cover']): - print 'Failed to read cover image from: %s' % title['cover'] - raise IOError - thumb = pw.CloneMagickWand(img) - if thumb < 0: - print 'generate_thumbnail(): Cannot clone cover' - raise RuntimeError - # img, width, height - pw.MagickThumbnailImage(thumb, 75, 100) - pw.MagickWriteImage(thumb, os.path.join(image_dir, thumb_file)) - pw.DestroyMagickWand(thumb) - except IOError: - print "generate_thumbnail() IOError with %s" % title['title'] - except RuntimeError: - print "generate_thumbnail() RuntimeError with %s" % title['title'] + with pw.ImageMagick(): + try: + img = pw.NewMagickWand() + if img < 0: + raise RuntimeError('generate_thumbnail(): Cannot create wand') + # Read the cover + if not pw.MagickReadImage(img, + title['cover'].encode(filesystem_encoding)): + print 'Failed to read cover image from: %s' % title['cover'] + raise IOError + thumb = pw.CloneMagickWand(img) + if thumb < 0: + print 'generate_thumbnail(): Cannot clone cover' + raise RuntimeError + # img, width, height + pw.MagickThumbnailImage(thumb, 75, 100) + pw.MagickWriteImage(thumb, os.path.join(image_dir, thumb_file)) + pw.DestroyMagickWand(thumb) + except IOError: + print "generate_thumbnail() IOError with %s" % title['title'] + except RuntimeError: + print "generate_thumbnail() RuntimeError with %s" % title['title'] def processSpecialTags(self, tags, this_title, opts): tag_list = [] From a7fca2fe615358200d9d9057ca12868fda2dce17 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Jan 2010 13:33:48 -0700 Subject: [PATCH 3/3] ... --- src/calibre/library/catalog.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index cc10fa981a..56d06572cf 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -663,47 +663,47 @@ class EPUB_MOBI(CatalogPlugin): # Methods def buildSources(self): - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 if not self.booksByTitle: self.fetchBooksByTitle() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.fetchBooksByAuthor() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLDescriptions() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLByTitle() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLByAuthor() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateHTMLByTags() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateThumbnails() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateOPF() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXHeader() - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXDescriptions("Descriptions") - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXByTitle("Titles", single_article_per_section=False) - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXByAuthor("Authors", single_article_per_section=False) - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateNCXByTags("Genres") - if self.reporter.cancel_requested: return 1 + if getattr(self.reporter, 'cancel_requested', False): return 1 self.writeNCX() return 0 @@ -1350,7 +1350,7 @@ class EPUB_MOBI(CatalogPlugin): for (i,title) in enumerate(self.booksByTitle): # Update status self.updateProgressMicroStep("generating thumbnails ...", - 100*i/len(self.booksByTitle)) + i/float(len(self.booksByTitle))) # Check to see if source file exists if 'cover' in title and os.path.isfile(title['cover']): # print "cover found for %s" % title['title']