Updated recipe ro the Times Online

This commit is contained in:
Kovid Goyal 2009-05-17 10:21:38 -07:00
parent 2bad2c5162
commit e8c56353df
3 changed files with 78 additions and 53 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

View File

@ -2,7 +2,7 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import re, time import re
from calibre import strftime from calibre import strftime
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
@ -12,6 +12,7 @@ class Newsweek(BasicNewsRecipe):
__author__ = 'Kovid Goyal' __author__ = 'Kovid Goyal'
description = 'Weekly news and current affairs in the US' description = 'Weekly news and current affairs in the US'
no_stylesheets = True no_stylesheets = True
encoding = 'utf-8'
language = _('English') language = _('English')
remove_tags = [ remove_tags = [
{'class':['navbar', 'ad', 'sponsorLinksArticle', 'mm-content', {'class':['navbar', 'ad', 'sponsorLinksArticle', 'mm-content',
@ -30,12 +31,12 @@ class Newsweek(BasicNewsRecipe):
def find_title(self, section): def find_title(self, section):
d = {'scope':'Scope', 'thetake':'The Take', 'features':'Features', d = {'scope':'Scope', 'thetake':'The Take', 'features':'Features',
None:'Departments'} None:'Departments', 'culture':'Culture'}
ans = None ans = None
a = section.find('a', attrs={'name':True}) a = section.find('a', attrs={'name':True})
if a is not None: if a is not None:
ans = a['name'] ans = a['name']
return d[ans] return d.get(ans, ans)
def find_articles(self, section): def find_articles(self, section):
@ -64,14 +65,6 @@ class Newsweek(BasicNewsRecipe):
soup = self.get_current_issue() soup = self.get_current_issue()
if not soup: if not soup:
raise RuntimeError('Unable to connect to newsweek.com. Try again later.') raise RuntimeError('Unable to connect to newsweek.com. Try again later.')
img = soup.find(alt='Cover')
if img is not None and img.has_key('src'):
small = img['src']
match = re.search(r'(\d+)_', small.rpartition('/')[-1])
if match is not None:
self.timefmt = strftime(' [%d %b, %Y]', time.strptime(match.group(1), '%y%m%d'))
self.cover_url = small.replace('coversmall', 'coverlarge')
sections = soup.findAll('div', attrs={'class':'featurewell'}) sections = soup.findAll('div', attrs={'class':'featurewell'})
titles = map(self.find_title, sections) titles = map(self.find_title, sections)
articles = map(self.find_articles, sections) articles = map(self.find_articles, sections)
@ -114,3 +107,12 @@ class Newsweek(BasicNewsRecipe):
href = a['href'].split('#')[0] href = a['href'].split('#')[0]
return self.index_to_soup(href) return self.index_to_soup(href)
def get_cover_url(self):
cover_url = None
soup = self.index_to_soup(self.INDEX)
link_item = soup.find('div',attrs={'class':'cover-image'})
if link_item and link_item.a and link_item.a.img:
cover_url = link_item.a.img['src']
return cover_url

View File

@ -1,42 +1,65 @@
#!/usr/bin/env python #!/usr/bin/env python
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Darko Miletic <darko.miletic at gmail.com>' __copyright__ = '2008-2009, Darko Miletic <darko.miletic at gmail.com>'
''' '''
timesonline.co.uk timesonline.co.uk
''' '''
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag
class TimesOnline(BasicNewsRecipe):
title = u'The Times Online' class Timesonline(BasicNewsRecipe):
__author__ = 'Darko Miletic' title = 'The Times Online'
description = 'UK news' __author__ = 'Darko Miletic'
oldest_article = 7 description = 'UK news'
max_articles_per_feed = 100 publisher = 'timesonline.co.uk'
no_stylesheets = True category = 'news, politics, UK'
use_embedded_content = False oldest_article = 2
language = _('English') max_articles_per_feed = 100
simultaneous_downloads = 1 no_stylesheets = True
use_embedded_content = False
remove_tags_after = dict(name='div', attrs={'class':'bg-666'}) simultaneous_downloads = 1
remove_tags = [ encoding = 'cp1252'
dict(name='div' , attrs={'class':'hide-from-print padding-bottom-7' }) lang = 'en-UK'
] language = _('English')
feeds = [ html2lrf_options = [
(u'Top stories from Times Online', u'http://www.timesonline.co.uk/tol/feeds/rss/topstories.xml' ), '--comment', description
('Latest Business News', 'http://www.timesonline.co.uk/tol/feeds/rss/business.xml'), , '--category', category
('Economics', 'http://www.timesonline.co.uk/tol/feeds/rss/economics.xml'), , '--publisher', publisher
('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'), html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"'
('Sports News', 'http://www.timesonline.co.uk/tol/feeds/rss/sport.xml'),
('Film News', 'http://www.timesonline.co.uk/tol/feeds/rss/film.xml'), remove_tags = [dict(name=['embed','object'])]
('Tech news', 'http://www.timesonline.co.uk/tol/feeds/rss/tech.xml'), remove_tags_after = dict(name='div', attrs={'class':'bg-666'})
('Literary Supplement', 'http://www.timesonline.co.uk/tol/feeds/rss/thetls.xml'),
] feeds = [
(u'Top stories from Times Online', u'http://www.timesonline.co.uk/tol/feeds/rss/topstories.xml' ),
def print_version(self, url): ('Latest Business News', 'http://www.timesonline.co.uk/tol/feeds/rss/business.xml'),
main = url.partition('#')[0] ('Economics', 'http://www.timesonline.co.uk/tol/feeds/rss/economics.xml'),
return main + '?print=yes' ('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'),
]
def print_version(self, url):
return url + '?print=yes'
def get_article_url(self, article):
return article.get('guid', None)
def preprocess_html(self, soup):
soup.html['xml:lang'] = self.lang
soup.html['lang'] = self.lang
mlang = Tag(soup,'meta',[("http-equiv","Content-Language"),("content",self.lang)])
mcharset = Tag(soup,'meta',[("http-equiv","Content-Type"),("content","text/html; charset=UTF-8")])
soup.head.insert(0,mlang)
soup.head.insert(1,mcharset)
return self.adeify_images(soup)