Merge from trunk

This commit is contained in:
Charles Haley 2011-05-22 19:49:18 +01:00
commit 6e4f885955
5 changed files with 87 additions and 68 deletions

BIN
recipes/icons/wash_post.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,64 +1,75 @@
__license__ = 'GPL v3'
__copyright__ = '2011, Darko Miletic <darko.miletic at gmail.com>'
'''
www.washingtonpost.com
'''
from calibre import strftime
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
class TheWashingtonPost(BasicNewsRecipe):
class WashingtonPost(BasicNewsRecipe): title = 'The Washington Post'
__author__ = 'Darko Miletic'
title = 'Washington Post' description = 'Leading source for news, video and opinion on politics, business, world and national news, science, travel, entertainment and more. Our local coverage includes reporting on education, crime, weather, traffic, real estate, jobs and cars for DC, Maryland and Virginia. Offering award-winning opinion writing, entertainment information and restaurant reviews.'
description = 'US political news' publisher = 'The Washington Post Company'
__author__ = 'Kovid Goyal' category = 'news, politics, USA'
use_embedded_content = False oldest_article = 2
max_articles_per_feed = 20 max_articles_per_feed = 200
language = 'en'
encoding = 'utf-8'
remove_javascript = True
no_stylesheets = True no_stylesheets = True
encoding = 'utf8'
delay = 1
use_embedded_content = False
language = 'en'
remove_empty_feeds = True
publication_type = 'newspaper'
masthead_url = 'http://www.washingtonpost.com/rw/sites/twpweb/img/logos/twp_logo_300.gif'
cover_url = strftime('http://www.washingtonpost.com/rw/WashingtonPost/Content/Epaper/%Y-%m-%d/Ax1.pdf')
extra_css = """
body{font-family: Georgia,serif }
"""
conversion_options = {
'comment' : description
, 'tags' : category
, 'publisher' : publisher
, 'language' : language
}
keep_only_tags = [dict(attrs={'id':['content','entryhead','entrytext']})]
remove_tags = [
dict(name=['meta','link','iframe','base'])
,dict(attrs={'id':'multimedia-leaf-page'})
]
remove_attributes= ['lang','property','epochtime','datetitle','pagetype','contenttype','comparetime']
feeds = [ feeds = [
('Politics', 'http://www.washingtonpost.com/rss/politics'), (u'World' , u'http://feeds.washingtonpost.com/rss/world' )
('Nation', 'http://www.washingtonpost.com/rss/national'), ,(u'National' , u'http://feeds.washingtonpost.com/rss/national' )
('World', 'http://www.washingtonpost.com/rss/world'), ,(u'White House' , u'http://feeds.washingtonpost.com/rss/politics/whitehouse' )
('Business', 'http://www.washingtonpost.com/rss/business'), ,(u'Business' , u'http://feeds.washingtonpost.com/rss/business' )
('Lifestyle', 'http://www.washingtonpost.com/rss/lifestyle'), ,(u'Opinions' , u'http://feeds.washingtonpost.com/rss/opinions' )
('Sports', 'http://www.washingtonpost.com/rss/sports'), ,(u'Investigations' , u'http://feeds.washingtonpost.com/rss/investigations' )
('Redskins', 'http://www.washingtonpost.com/rss/sports/redskins'), ,(u'Local' , u'http://feeds.washingtonpost.com/rss/local' )
('Opinions', 'http://www.washingtonpost.com/rss/opinions'), ,(u'Entertainment' , u'http://feeds.washingtonpost.com/rss/entertainment' )
('Entertainment', 'http://www.washingtonpost.com/rss/entertainment'), ,(u'Sports' , u'http://feeds.washingtonpost.com/rss/sports' )
('Local', 'http://www.washingtonpost.com/rss/local'), ,(u'Redskins' , u'http://feeds.washingtonpost.com/rss/sports/redskins' )
('Investigations', ,(u'Special Reports', u'http://feeds.washingtonpost.com/rss/national/special-reports')
'http://www.washingtonpost.com/rss/investigations'),
] ]
remove_tags = [
{'class':lambda x: x and 'article-toolbar' in x},
{'class':lambda x: x and 'quick-comments' in x},
{'class':lambda x: x and 'tweet' in x},
{'class':lambda x: x and 'article-related' in x},
{'class':lambda x: x and 'hidden' in x.split()},
{'class':lambda x: x and 'also-read' in x.split()},
{'class':lambda x: x and 'partners-content' in x.split()},
{'class':['module share', 'module ads', 'comment-vars', 'hidden',
'share-icons-wrap', 'comments', 'flipper']},
{'id':['right-rail', 'save-and-share']},
{'width':'1', 'height':'1'},
]
keep_only_tags = dict(id=['content', 'article'])
def get_article_url(self, *args):
ans = BasicNewsRecipe.get_article_url(self, *args)
ans = ans.rpartition('?')[0]
if ans.endswith('_video.html'):
return None
if 'ads.pheedo.com' in ans:
return None
#if not ans.endswith('_blog.html'):
# return None
return ans
def print_version(self, url): def print_version(self, url):
return url.replace('_story.html', '_singlePage.html') if '_story.html' in url:
return url.replace('_story.html','_print.html')
return url
def get_article_url(self, article):
link = BasicNewsRecipe.get_article_url(self,article)
if not 'washingtonpost.com' in link:
self.log('Skipping adds:', link)
return None
for it in ['_video.html','_gallery.html','_links.html']:
if it in link:
self.log('Skipping non-article:', link)
return None
return link

View File

@ -16,7 +16,7 @@ from calibre.gui2 import error_dialog, Dispatcher, warning_dialog
from calibre.gui2.dialogs.progress import ProgressDialog from calibre.gui2.dialogs.progress import ProgressDialog
from calibre.utils.config import prefs, tweaks from calibre.utils.config import prefs, tweaks
class Worker(Thread): class Worker(Thread): # {{{
def __init__(self, ids, db, loc, progress, done, delete_after): def __init__(self, ids, db, loc, progress, done, delete_after):
Thread.__init__(self) Thread.__init__(self)
@ -75,7 +75,7 @@ class Worker(Thread):
if co is not None: if co is not None:
newdb.set_conversion_options(x, 'PIPE', co) newdb.set_conversion_options(x, 'PIPE', co)
self.processed.add(x) self.processed.add(x)
# }}}
class CopyToLibraryAction(InterfaceAction): class CopyToLibraryAction(InterfaceAction):

View File

@ -41,10 +41,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{
50 + 40 * sin(0.8 * i * pi)) 50 + 40 * sin(0.8 * i * pi))
self.star_path.closeSubpath() self.star_path.closeSubpath()
self.star_path.setFillRule(Qt.WindingFill) self.star_path.setFillRule(Qt.WindingFill)
gradient = QLinearGradient(0, 0, 0, 100) self.gradient = QLinearGradient(0, 0, 0, 100)
gradient.setColorAt(0.0, self.COLOR)
gradient.setColorAt(1.0, self.COLOR)
self.brush = QBrush(gradient)
self.factor = self.SIZE/100. self.factor = self.SIZE/100.
def sizeHint(self, option, index): def sizeHint(self, option, index):
@ -52,7 +49,10 @@ class RatingDelegate(QStyledItemDelegate): # {{{
return QSize(5*(self.SIZE), self.SIZE+4) return QSize(5*(self.SIZE), self.SIZE+4)
def paint(self, painter, option, index): def paint(self, painter, option, index):
style = self._parent.style()
option = QStyleOptionViewItemV4(option)
self.initStyleOption(option, index) self.initStyleOption(option, index)
option.text = u''
num = index.model().data(index, Qt.DisplayRole).toInt()[0] num = index.model().data(index, Qt.DisplayRole).toInt()[0]
def draw_star(): def draw_star():
painter.save() painter.save()
@ -64,7 +64,10 @@ class RatingDelegate(QStyledItemDelegate): # {{{
painter.restore() painter.restore()
painter.save() painter.save()
if option.state & QStyle.State_Selected: if hasattr(QStyle, 'CE_ItemViewItem'):
style.drawControl(QStyle.CE_ItemViewItem, option,
painter, self._parent)
elif option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight()) painter.fillRect(option.rect, option.palette.highlight())
else: else:
painter.fillRect(option.rect, option.backgroundBrush) painter.fillRect(option.rect, option.backgroundBrush)
@ -74,14 +77,15 @@ class RatingDelegate(QStyledItemDelegate): # {{{
painter.setClipRect(option.rect) painter.setClipRect(option.rect)
y = option.rect.center().y()-self.SIZE/2. y = option.rect.center().y()-self.SIZE/2.
x = option.rect.left() x = option.rect.left()
brush = index.model().data(index, role=Qt.ForegroundRole) color = index.data(Qt.ForegroundRole)
if brush is None: if color.isNull() or not color.isValid():
pen = self.PEN color = self.COLOR
painter.setBrush(self.COLOR)
else: else:
pen = QPen(brush, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) color = QColor(color)
painter.setBrush(brush) painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
painter.setPen(pen) self.gradient.setColorAt(0.0, color)
self.gradient.setColorAt(1.0, color)
painter.setBrush(QBrush(self.gradient))
painter.translate(x, y) painter.translate(x, y)
i = 0 i = 0
while i < num: while i < num:

View File

@ -29,6 +29,10 @@ def remove_dir(x):
def base_dir(): def base_dir():
global _base_dir global _base_dir
if _base_dir is not None and not os.path.exists(_base_dir):
# Some people seem to think that running temp file cleaners that
# delete the temp dirs of running programs is a good idea!
_base_dir = None
if _base_dir is None: if _base_dir is None:
td = os.environ.get('CALIBRE_WORKER_TEMP_DIR', None) td = os.environ.get('CALIBRE_WORKER_TEMP_DIR', None)
if td is not None: if td is not None: