GwR fix for options passable as lists or strings

This commit is contained in:
GRiker 2010-01-22 14:24:26 -07:00
commit e90d19775c
7 changed files with 96 additions and 47 deletions

View File

@ -122,6 +122,9 @@
- title: Editor and Publisher - title: Editor and Publisher
author: XanthanGum author: XanthanGum
- title: The Week (free)
author: Darko Miletic
improved recipes: improved recipes:
- Physics Today - Physics Today
- Wall Street Journal - Wall Street Journal

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

View File

@ -0,0 +1,49 @@
__license__ = 'GPL v3'
__copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
'''
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')
]

View File

@ -44,6 +44,7 @@ class PluginWidget(QWidget,Ui_Form):
for opt in self.OPTION_FIELDS: for opt in self.OPTION_FIELDS:
opt_value = unicode(getattr(self, opt[0]).text()) opt_value = unicode(getattr(self, opt[0]).text())
gprefs.set(self.name + '_' + opt[0], opt_value) gprefs.set(self.name + '_' + opt[0], opt_value)
if opt[0] != 'exclude_genre':
opt_value = opt_value.split(',') opt_value = opt_value.split(',')
opts_dict[opt[0]] = opt_value opts_dict[opt[0]] = opt_value

View File

@ -49,7 +49,10 @@ def gui_catalog(fmt, title, dbspec, ids, out_file_name, fmt_options,
# Extract the option dictionary to comma-separated lists # Extract the option dictionary to comma-separated lists
for option in fmt_options: for option in fmt_options:
if isinstance(fmt_options[option],list):
setattr(opts,option, ','.join(fmt_options[option])) setattr(opts,option, ','.join(fmt_options[option]))
else:
setattr(opts,option, fmt_options[option])
# Fetch and run the plugin for fmt # Fetch and run the plugin for fmt
plugin = plugin_for_catalog_format(fmt) plugin = plugin_for_catalog_format(fmt)

View File

@ -36,9 +36,6 @@ class Catalog(QDialog, Ui_Dialog):
self.title.setText(dynamic.get('catalog_last_used_title', self.title.setText(dynamic.get('catalog_last_used_title',
_('My Books'))) _('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 = [], [] self.fmts, self.widgets = [], []
from calibre.customize.builtins import plugins as builtin_plugins from calibre.customize.builtins import plugins as builtin_plugins

View File

@ -6,7 +6,7 @@ from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag,
from calibre.customize import CatalogPlugin from calibre.customize import CatalogPlugin
from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.customize.conversion import OptionRecommendation, DummyReporter from calibre.customize.conversion import OptionRecommendation, DummyReporter
from calibre import filesystem_encoding
FIELDS = ['all', 'author_sort', 'authors', 'comments', FIELDS = ['all', 'author_sort', 'authors', 'comments',
'cover', 'formats', 'id', 'isbn', 'pubdate', 'publisher', 'rating', 'cover', 'formats', 'id', 'isbn', 'pubdate', 'publisher', 'rating',
@ -663,47 +663,47 @@ class EPUB_MOBI(CatalogPlugin):
# Methods # Methods
def buildSources(self): def buildSources(self):
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
if not self.booksByTitle: if not self.booksByTitle:
self.fetchBooksByTitle() self.fetchBooksByTitle()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.fetchBooksByAuthor() self.fetchBooksByAuthor()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateHTMLDescriptions() self.generateHTMLDescriptions()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateHTMLByTitle() self.generateHTMLByTitle()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateHTMLByAuthor() self.generateHTMLByAuthor()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateHTMLByTags() self.generateHTMLByTags()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateThumbnails() self.generateThumbnails()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateOPF() self.generateOPF()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateNCXHeader() self.generateNCXHeader()
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.generateNCXDescriptions("Descriptions") 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) 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) 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") self.generateNCXByTags("Genres")
if self.reporter.cancel_requested: return 1 if getattr(self.reporter, 'cancel_requested', False): return 1
self.writeNCX() self.writeNCX()
return 0 return 0
@ -1350,7 +1350,7 @@ class EPUB_MOBI(CatalogPlugin):
for (i,title) in enumerate(self.booksByTitle): for (i,title) in enumerate(self.booksByTitle):
# Update status # Update status
self.updateProgressMicroStep("generating thumbnails ...", self.updateProgressMicroStep("generating thumbnails ...",
100*i/len(self.booksByTitle)) i/float(len(self.booksByTitle)))
# Check to see if source file exists # Check to see if source file exists
if 'cover' in title and os.path.isfile(title['cover']): if 'cover' in title and os.path.isfile(title['cover']):
# print "cover found for %s" % title['title'] # print "cover found for %s" % title['title']
@ -2456,12 +2456,14 @@ class EPUB_MOBI(CatalogPlugin):
def generateThumbnail(self, title, image_dir, thumb_file): def generateThumbnail(self, title, image_dir, thumb_file):
import calibre.utils.PythonMagickWand as pw import calibre.utils.PythonMagickWand as pw
with pw.ImageMagick():
try: try:
img = pw.NewMagickWand() img = pw.NewMagickWand()
if img < 0: if img < 0:
raise RuntimeError('generate_thumbnail(): Cannot create wand') raise RuntimeError('generate_thumbnail(): Cannot create wand')
# Read the cover # Read the cover
if not pw.MagickReadImage(img, title['cover']): if not pw.MagickReadImage(img,
title['cover'].encode(filesystem_encoding)):
print 'Failed to read cover image from: %s' % title['cover'] print 'Failed to read cover image from: %s' % title['cover']
raise IOError raise IOError
thumb = pw.CloneMagickWand(img) thumb = pw.CloneMagickWand(img)
@ -2482,16 +2484,10 @@ class EPUB_MOBI(CatalogPlugin):
for tag in tags: for tag in tags:
tag = self.convertHTMLEntities(tag) tag = self.convertHTMLEntities(tag)
if tag.startswith(opts.note_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:] this_title['notes'] = tag[1:]
elif tag == opts.read_tag: elif tag == opts.read_tag:
# if opts.verbose:
# print "%s marked as read" % this_title['title']
this_title['read'] = True this_title['read'] = True
elif re.search(opts.exclude_genre, tag): elif re.search(opts.exclude_genre, tag):
# if opts.verbose:
# print "'%s' matches exclude_genre regex, skipping" % tag
continue continue
else: else:
tag_list.append(tag) tag_list.append(tag)