Merge from trunk

This commit is contained in:
Charles Haley 2011-11-08 07:51:08 +01:00
commit 5944a4126d
5 changed files with 57 additions and 6 deletions

View File

@ -8,6 +8,11 @@ from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag, NavigableString
class TheIndependentNew(BasicNewsRecipe):
#used for converting rating to stars
_STAR_URL = 'http://www.independent.co.uk/skins/ind/images/rating_star.png'
_NO_STAR_URL = 'http://www.independent.co.uk/skins/ind/images/rating_star_grey.png'
title = u'The Independent'
__author__ = 'Will'
description = 'The latest in UK News and World News from The \
@ -44,12 +49,26 @@ class TheIndependentNew(BasicNewsRecipe):
h1{font-family: Georgia,serif }
body{font-family: Verdana,Arial,Helvetica,sans-serif}
img{margin-bottom: 0.4em; display:block}
.byline,.image,.dateline{font-size: x-small; color:#888888}
.starRating img {float: left}
.starRating {margin-top:0.4em; display: block}
.image {clear:left; font-size: x-small; color:#888888;}
.articleByTimeLocation {font-size: x-small; color:#888888;
margin-bottom:0.2em ; margin-top:0.2em ; display:block}
.subtitle {clear:left}
.column-1 h1 { color: #191919}
.column-1 h2 { color: #333333}
.column-1 h3 { color: #444444}
.column-1 p { color: #777777}
.column-1 p,a,h1,h2,h3 { margin: 0; }
.column-1 div{color:#888888; margin: 0;}
.articleContent {display: block; clear:left;}
"""
oldest_article = 1
max_articles_per_feed = 100
def preprocess_html(self, soup):
for item in soup.findAll(attrs={'class' : re.compile("widget.*")}):
remove = True
@ -115,13 +134,40 @@ class TheIndependentNew(BasicNewsRecipe):
subtitle.extract()
#replace rating numbers with stars
for item in soup.findAll('div',attrs={ 'class' : 'starRating'}):
if item is not None:
soup2 = self._insertRatingStars(soup,item)
if soup2 is not None:
soup = soup2
return soup
def _insertRatingStars(self,soup,item):
if item.contents is None:
return
rating = item.contents[0]
if not rating.isdigit():
return None
rating = int(item.contents[0])
for i in range(1,6):
star = Tag(soup,'img')
if i <= rating:
star['src'] = self._STAR_URL
else:
star['src'] = self._NO_STAR_URL
star['alt'] = 'star number ' + str(i)
item.insert(i,star)
#item.contents[0] = NavigableString('(' + str(rating) + ')')
item.contents[0] = ''
def postprocess_html(self,soup, first_fetch):
#find broken images and remove captions
for item in soup.findAll('div', attrs={'class' : 'byline'}):
for item in soup.findAll('div', attrs={'class' : 'image'}):
img = item.findNext('img')
if img is not None and img['src'] is not None:
# broken images still point to remote url

View File

@ -66,4 +66,6 @@ Various things that require other things before they can be migrated:
functionality.
2. Catching DatabaseException and sqlite.Error when creating new
libraries/switching/on calibre startup.
3. From refresh in the legacy interface: Rember to flush the composite
column template cache.
'''

View File

@ -48,6 +48,7 @@ class Cache(object):
self.read_lock, self.write_lock = create_locks()
self.record_lock = RecordLock(self.read_lock)
self.format_metadata_cache = defaultdict(dict)
self.formatter_template_cache = {}
# Implement locking for all simple read/write API methods
# An unlocked version of the method is stored with the name starting
@ -89,7 +90,7 @@ class Cache(object):
return self.backend.format_abspath(book_id, fmt, name, path)
def _get_metadata(self, book_id, get_user_categories=True): # {{{
mi = Metadata(None)
mi = Metadata(None, template_cache=self.formatter_template_cache)
author_ids = self._field_ids_for('authors', book_id)
aut_list = [self._author_data(i) for i in author_ids]
aum = []

View File

@ -233,7 +233,7 @@ class TREKSTOR(USBMS):
VENDOR_NAME = 'TREKSTOR'
WINDOWS_MAIN_MEM = WINDOWS_CARD_A_MEM = ['EBOOK_PLAYER_7',
'EBOOK_PLAYER_5M']
'EBOOK_PLAYER_5M', 'EBOOK-READER_3.0']
class EEEREADER(USBMS):

View File

@ -173,6 +173,8 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250,
tsorder = tweaks['save_template_title_series_sorting']
format_args = FORMAT_ARGS.copy()
format_args.update(mi.all_non_none_fields())
if mi.is_null('author_sort'):
format_args['author_sort'] = _('Unknown')
if mi.title:
if tsorder == 'strictly_alphabetic':
v = mi.title