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 0000000000..a7058ce2a2 Binary files /dev/null and b/resources/images/news/the_week_magazine_free.png differ 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') + ] + + diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py index acb158a05f..9b9911b5d4 100644 --- a/src/calibre/gui2/catalog/catalog_epub_mobi.py +++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py @@ -44,7 +44,8 @@ class PluginWidget(QWidget,Ui_Form): for opt in self.OPTION_FIELDS: opt_value = unicode(getattr(self, opt[0]).text()) gprefs.set(self.name + '_' + opt[0], opt_value) - opt_value = opt_value.split(',') + if opt[0] != 'exclude_genre': + opt_value = opt_value.split(',') opts_dict[opt[0]] = opt_value opts_dict['output_profile'] = [load_defaults('page_setup')['output_profile']] diff --git a/src/calibre/gui2/convert/gui_conversion.py b/src/calibre/gui2/convert/gui_conversion.py index 7941586274..67c50758f8 100644 --- a/src/calibre/gui2/convert/gui_conversion.py +++ b/src/calibre/gui2/convert/gui_conversion.py @@ -49,7 +49,10 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, fmt_options, # Extract the option dictionary to comma-separated lists for option in fmt_options: - setattr(opts,option, ','.join(fmt_options[option])) + if isinstance(fmt_options[option],list): + setattr(opts,option, ','.join(fmt_options[option])) + else: + setattr(opts,option, fmt_options[option]) # Fetch and run the plugin for fmt plugin = plugin_for_catalog_format(fmt) diff --git a/src/calibre/gui2/dialogs/catalog.py b/src/calibre/gui2/dialogs/catalog.py index 56f2bd1f6f..7009824679 100644 --- a/src/calibre/gui2/dialogs/catalog.py +++ b/src/calibre/gui2/dialogs/catalog.py @@ -36,9 +36,6 @@ class Catalog(QDialog, Ui_Dialog): self.title.setText(dynamic.get('catalog_last_used_title', _('My Books'))) - # GwR *** Add option tabs for built-in formats - # This code models #69 in calibre/gui2/dialogs/config/__init__.py - self.fmts, self.widgets = [], [] from calibre.customize.builtins import plugins as builtin_plugins diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index 7feb846216..b62d1a0f29 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', @@ -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'] @@ -2456,42 +2456,38 @@ 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 = [] for tag in tags: tag = self.convertHTMLEntities(tag) if tag.startswith(opts.note_tag): - # if opts.verbose: - # print "%s has a note: %s" % (this_title['title'], tag[1:]) this_title['notes'] = tag[1:] elif tag == opts.read_tag: - # if opts.verbose: - # print "%s marked as read" % this_title['title'] this_title['read'] = True elif re.search(opts.exclude_genre, tag): - # if opts.verbose: - # print "'%s' matches exclude_genre regex, skipping" % tag continue else: tag_list.append(tag)