This commit is contained in:
Fabian Graßl 2010-10-08 12:33:36 +02:00
commit e90af71b77
8 changed files with 156 additions and 103 deletions

View File

@ -0,0 +1,30 @@
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1286477122(BasicNewsRecipe):
title = u'Il Fatto Quotidiano'
oldest_article = 7
max_articles_per_feed = 25
language = 'it'
__author__ = 'egilh'
feeds = [
(u'Politica & Palazzo', u'http://www.ilfattoquotidiano.it/category/politica-palazzo/feed/'),
(u'Giustizia & impunit\xe0', u'http://www.ilfattoquotidiano.it/category/giustizia-impunita/feed/'),
(u'Media & regime', u'http://www.ilfattoquotidiano.it/category/media-regime/feed/'),
(u'Economia & Lobby', u'http://www.ilfattoquotidiano.it/category/economia-lobby/feed/'),
(u'Lavoro & precari', u'http://www.ilfattoquotidiano.it/category/lavoro-precari/feed/'),
(u'Ambiente & Veleni', u'http://www.ilfattoquotidiano.it/category/ambiente-veleni/feed/'),
(u'Sport & miliardi', u'http://www.ilfattoquotidiano.it/category/sport-miliardi/feed/'),
(u'Cronaca', u'http://www.ilfattoquotidiano.it/category/cronaca/feed/'),
(u'Mondo', u'http://www.ilfattoquotidiano.it/category/mondo/feed/'),
(u'Societ\xe0', u'http://www.ilfattoquotidiano.it/category/societa/feed/'),
(u'Scuola', u'http://www.ilfattoquotidiano.it/category/scuola/feed/'),
(u'Tecno', u'http://www.ilfattoquotidiano.it/category/tecno/feed/'),
(u'Terza pagina', u'http://www.ilfattoquotidiano.it/category/terza-pagina/feed/'),
(u'Piacere quotidiano', u'http://www.ilfattoquotidiano.it/category/piacere-quotidiano/feed/'),
(u'Cervelli in fuga', u'http://www.ilfattoquotidiano.it/category/cervelli-in-fuga/feed/'),
(u'Documentati!', u'http://www.ilfattoquotidiano.it/category/documentati/feed/'),
(u'Misfatto', u'http://www.ilfattoquotidiano.it/category/misfatto/feed/')
]

View File

@ -1,103 +1,106 @@
#!/usr/bin/env python
__license__ = 'GPL v3'
__copyright__ = '2008-2009, Darko Miletic <darko.miletic at gmail.com>'
__copyright__ = '2009-2010, Darko Miletic <darko.miletic at gmail.com>'
'''
timesonline.co.uk
www.thetimes.co.uk
'''
import re
import urllib
from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import Tag
class Timesonline(BasicNewsRecipe):
title = 'The Times Online'
__author__ = 'Darko Miletic and Sujata Raman'
description = 'UK news'
publisher = 'timesonline.co.uk'
class TimesOnline(BasicNewsRecipe):
title = 'The Times UK'
__author__ = 'Darko Miletic'
description = 'news from United Kingdom and World'
language = 'en_GB'
publisher = 'Times Newspapers Ltd'
category = 'news, politics, UK'
oldest_article = 2
oldest_article = 3
max_articles_per_feed = 100
no_stylesheets = True
use_embedded_content = False
simultaneous_downloads = 1
encoding = 'ISO-8859-1'
remove_javascript = True
language = 'en_GB'
recursions = 9
match_regexps = [r'http://www.timesonline.co.uk/.*page=[2-9]']
encoding = 'utf-8'
delay = 1
needs_subscription = True
publication_type = 'newspaper'
masthead_url = 'http://www.thetimes.co.uk/tto/public/img/the_times_460.gif'
INDEX = 'http://www.thetimes.co.uk'
PREFIX = u'http://www.thetimes.co.uk/tto/'
extra_css = """
.f-ha{font-size: xx-large; font-weight: bold}
.f-author{font-family: Arial,Helvetica,sans-serif}
.caption{font-size: small}
body{font-family: Georgia,"Times New Roman",Times,serif}
"""
conversion_options = {
'comment' : description
, 'tags' : category
, 'publisher' : publisher
, 'language' : language
}
preprocess_regexps = [(re.compile(r'<!--.*?-->', re.DOTALL), lambda m: '')]
keep_only_tags = [
dict(name='div', attrs= {'id':['region-column1and2-layout2']}),
{'class' : ['subheading']},
dict(name='div', attrs= {'id':['dynamic-image-holder']}),
dict(name='div', attrs= {'class':['article-author']}),
dict(name='div', attrs= {'id':['related-article-links']}),
]
def get_browser(self):
br = BasicNewsRecipe.get_browser()
br.open('http://www.timesplus.co.uk/tto/news/?login=false&url=http://www.thetimes.co.uk/tto/news/?lightbox=false')
if self.username is not None and self.password is not None:
data = urllib.urlencode({ 'userName':self.username
,'password':self.password
,'keepMeLoggedIn':'false'
})
br.open('https://www.timesplus.co.uk/iam/app/authenticate',data)
return br
remove_tags = [
dict(name=['embed','object','form','iframe']),
dict(name='span', attrs = {'class':'float-left padding-left-8 padding-top-2'}),
dict(name='div', attrs= {'id':['region-footer','region-column2-layout2','grid-column4','login-status','comment-sort-order']}),
dict(name='div', attrs= {'class': ['debate-quote-container','clear','your-comment','float-left related-attachements-container','float-left padding-bottom-5 padding-top-8','puff-top']}),
dict(name='span', attrs = {'id': ['comment-count']}),
dict(name='ul',attrs = {'id': 'read-all-comments'}),
dict(name='a', attrs = {'class':'reg-bold'}),
dict(name=['object','link','iframe','base','meta'])
,dict(attrs={'class':'tto-counter' })
]
remove_attributes=['lang']
keep_only_tags = [
dict(attrs={'class':'heading' })
,dict(attrs={'class':'f-author'})
,dict(attrs={'id':'bodycopy'})
]
extra_css = '''
.small{font-family :Arial,Helvetica,sans-serif; font-size:x-small;}
.byline{font-family :Arial,Helvetica,sans-serif; font-size:x-small; background:#F8F1D8;}
.color-666{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#666666; }
h1{font-family:Georgia,Times New Roman,Times,serif;font-size:large; }
.color-999 {color:#999999;}
.x-small {font-size:x-small;}
#related-article-links{font-family :Arial,Helvetica,sans-serif; font-size:small;}
h2{color:#333333;font-family :Georgia,Times New Roman,Times,serif; font-size:small;}
p{font-family :Arial,Helvetica,sans-serif; font-size:small;}
'''
feeds = [
(u'Top stories from Times Online', u'http://www.timesonline.co.uk/tol/feeds/rss/topstories.xml' ),
('Latest Business News', 'http://www.timesonline.co.uk/tol/feeds/rss/business.xml'),
('Economics', 'http://www.timesonline.co.uk/tol/feeds/rss/economics.xml'),
('World News', 'http://www.timesonline.co.uk/tol/feeds/rss/worldnews.xml'),
('UK News', 'http://www.timesonline.co.uk/tol/feeds/rss/uknews.xml'),
('Travel News', 'http://www.timesonline.co.uk/tol/feeds/rss/travel.xml'),
('Sports News', 'http://www.timesonline.co.uk/tol/feeds/rss/sport.xml'),
('Film News', 'http://www.timesonline.co.uk/tol/feeds/rss/film.xml'),
('Tech news', 'http://www.timesonline.co.uk/tol/feeds/rss/tech.xml'),
('Literary Supplement', 'http://www.timesonline.co.uk/tol/feeds/rss/thetls.xml'),
(u'UK News' , PREFIX + u'news/uk/?view=list' )
,(u'World' , PREFIX + u'news/world/?view=list' )
,(u'Politics' , PREFIX + u'news/politics/?view=list')
,(u'Health' , PREFIX + u'health/news/?view=list' )
,(u'Education' , PREFIX + u'education/?view=list' )
,(u'Technology' , PREFIX + u'technology/?view=list' )
,(u'Science' , PREFIX + u'science/?view=list' )
,(u'Environment' , PREFIX + u'environment/?view=list' )
,(u'Faith' , PREFIX + u'faith/?view=list' )
,(u'Opinion' , PREFIX + u'opinion/?view=list' )
,(u'Sport' , PREFIX + u'sport/?view=list' )
,(u'Business' , PREFIX + u'business/?view=list' )
,(u'Money' , PREFIX + u'money/?view=list' )
,(u'Life' , PREFIX + u'life/?view=list' )
,(u'Arts' , PREFIX + u'arts/?view=list' )
]
def get_cover_url(self):
cover_url = None
index = 'http://www.timesonline.co.uk/tol/newspapers/'
soup = self.index_to_soup(index)
link_item = soup.find(name = 'div',attrs ={'class': "float-left margin-right-15"})
if link_item:
cover_url = link_item.img['src']
return cover_url
def get_article_url(self, article):
return article.get('guid', None)
def preprocess_html(self, soup):
soup.html['xml:lang'] = self.language
soup.html['lang'] = self.language
mlang = Tag(soup,'meta',[("http-equiv","Content-Language"),("content",self.language)])
mcharset = Tag(soup,'meta',[("http-equiv","Content-Type"),("content","text/html; charset=ISO-8859-1")])
soup.head.insert(0,mlang)
soup.head.insert(1,mcharset)
for item in soup.findAll(style=True):
del item['style']
return self.adeify_images(soup)
def postprocess_html(self,soup,first):
for tag in soup.findAll(text = ['Previous Page','Next Page']):
tag.extract()
return soup
def parse_index(self):
totalfeeds = []
lfeeds = self.get_feeds()
for feedobj in lfeeds:
feedtitle, feedurl = feedobj
self.report_progress(0, _('Fetching feed')+' %s...'%(feedtitle if feedtitle else feedurl))
articles = []
soup = self.index_to_soup(feedurl)
for item in soup.findAll('td', attrs={'class':'title'}):
atag = item.find('a')
url = self.INDEX + atag['href']
title = self.tag_to_string(atag)
articles.append({
'title' :title
,'date' :''
,'url' :url
,'description':''
})
totalfeeds.append((feedtitle, articles))
return totalfeeds

View File

@ -19,7 +19,6 @@ from calibre.ebooks.metadata.epub import set_metadata
from calibre.library.server.utils import strftime
from calibre.utils.config import config_dir, prefs
from calibre.utils.date import isoformat, now, parse_date
from calibre.utils.localization import get_lang
from calibre.utils.logging import Log
from calibre.utils.zipfile import ZipFile

View File

@ -101,7 +101,6 @@ STANDARD_METADATA_FIELDS = SOCIAL_METADATA_FIELDS.union(
CALIBRE_METADATA_FIELDS)
# Metadata fields that smart update must do special processing to copy.
SC_FIELDS_NOT_COPIED = frozenset(['title', 'title_sort', 'authors',
'author_sort', 'author_sort_map',
'cover_data', 'tags', 'language',
@ -124,5 +123,6 @@ SERIALIZABLE_FIELDS = SOCIAL_METADATA_FIELDS.union(
PUBLICATION_METADATA_FIELDS).union(
CALIBRE_METADATA_FIELDS).union(
DEVICE_METADATA_FIELDS) - \
frozenset(['device_collections', 'formats'])
frozenset(['device_collections', 'formats',
'cover_data'])
# these are rebuilt when needed

View File

@ -147,26 +147,32 @@ class ChooseLibraryAction(InterfaceAction):
self.qs_locations = [i[1] for i in locations]
self.rename_menu.clear()
self.delete_menu.clear()
quick_actions = []
quick_actions, rename_actions, delete_actions = [], [], []
for name, loc in locations:
ac = self.quick_menu.addAction(name, Dispatcher(partial(self.switch_requested,
loc)))
quick_actions.append(ac)
self.rename_menu.addAction(name, Dispatcher(partial(self.rename_requested,
ac = self.rename_menu.addAction(name, Dispatcher(partial(self.rename_requested,
name, loc)))
self.delete_menu.addAction(name, Dispatcher(partial(self.delete_requested,
rename_actions.append(ac)
ac = self.delete_menu.addAction(name, Dispatcher(partial(self.delete_requested,
name, loc)))
delete_actions.append(ac)
qs_actions = []
for i, x in enumerate(locations[:len(self.switch_actions)]):
name, loc = x
ac = self.switch_actions[i]
ac.setText(name)
ac.setVisible(True)
qs_actions.append(ac)
self.quick_menu_action.setVisible(bool(locations))
self.rename_menu_action.setVisible(bool(locations))
self.delete_menu_action.setVisible(bool(locations))
self.gui.location_manager.set_switch_actions(quick_actions)
self.gui.location_manager.set_switch_actions(quick_actions,
rename_actions, delete_actions, qs_actions,
self.action_choose)
def location_selected(self, loc):

View File

@ -24,7 +24,6 @@ class LocationManager(QObject): # {{{
locations_changed = pyqtSignal()
unmount_device = pyqtSignal()
location_selected = pyqtSignal(object)
switch_actions_set = pyqtSignal(object)
def __init__(self, parent=None):
QObject.__init__(self, parent)
@ -70,12 +69,23 @@ class LocationManager(QObject): # {{{
ac('cardb', _('Card B'), 'sd.png',
_('Show books in storage card B'))
def set_switch_actions(self, actions):
def set_switch_actions(self, quick_actions, rename_actions, delete_actions,
switch_actions, choose_action):
self.switch_menu = QMenu()
for ac in actions:
self.switch_menu.addAction(choose_action)
self.cs_menus = []
for t, acs in [(_('Quick switch'), quick_actions),
(_('Rename library'), rename_actions),
(_('Delete library'), delete_actions)]:
if acs:
self.cs_menus.append(QMenu(t))
for ac in acs:
self.cs_menus[-1].addAction(ac)
self.switch_menu.addMenu(self.cs_menus[-1])
self.switch_menu.addSeparator()
for ac in switch_actions:
self.switch_menu.addAction(ac)
self.library_action.setMenu(self.switch_menu)
self.switch_actions_set.emit(bool(actions))
def _location_selected(self, location, *args):
if location != self.current_location and hasattr(self,

View File

@ -144,10 +144,10 @@ class DownloadMetadata(Thread):
def commit_covers(self, all=False):
if all:
self.worker.jobs.put(False)
self.worker.jobs.put((False, False))
while True:
try:
id, fmi, ok, cdata = self.worker.results.get(False)
id, fmi, ok, cdata = self.worker.results.get_nowait()
if ok:
self.fetched_covers[id] = cdata
self.results.put((id, 'cover', ok, fmi.title))
@ -210,6 +210,12 @@ class DoDownload(QObject):
pass
if not self.downloader.is_alive():
self.timer.stop()
while True:
try:
r = self.downloader.results.get_nowait()
self.handle_result(r)
except Empty:
break
self.pd.accept()
def handle_result(self, r):

View File

@ -1010,7 +1010,6 @@ def command_restore_database(args, dbpath):
'saved to', name)
def list_categories_option_parser():
from calibre.library.check_library import CHECKS
parser = get_parser(_('''\
%prog list_categories [options]