Update NZZ

This commit is contained in:
Kovid Goyal 2013-12-18 09:47:45 +05:30
parent d51a0be334
commit 480cc884fe
2 changed files with 37 additions and 31 deletions

View File

@ -1,4 +1,3 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2009-2010, Darko Miletic <darko.miletic at gmail.com>, 2012 Bernd Leinfelder <skoll1975@gmail.com>' __copyright__ = '2009-2010, Darko Miletic <darko.miletic at gmail.com>, 2012 Bernd Leinfelder <skoll1975@gmail.com>'
@ -41,7 +40,6 @@ class Nzz(BasicNewsRecipe):
,'publisher' : publisher ,'publisher' : publisher
} }
remove_attributes=['width','height','lang'] remove_attributes=['width','height','lang']
remove_tags_before = dict(id='main') remove_tags_before = dict(id='main')
remove_tags_after = dict(id='articleBodyText') remove_tags_after = dict(id='articleBodyText')

View File

@ -1,3 +1,4 @@
import re
from calibre import strftime from calibre import strftime
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -7,6 +8,7 @@ __copyright__ = '2012, Bernd Leinfelder <skoll1975 at gmail.com> '
webpaper.nzz.ch webpaper.nzz.ch
''' '''
from calibre.ptempfile import PersistentTemporaryFile
from calibre.web.feeds.recipes import BasicNewsRecipe from calibre.web.feeds.recipes import BasicNewsRecipe
class Nzz(BasicNewsRecipe): class Nzz(BasicNewsRecipe):
@ -23,6 +25,7 @@ class Nzz(BasicNewsRecipe):
encoding = 'utf-8' encoding = 'utf-8'
use_embedded_content = False use_embedded_content = False
language = 'de' language = 'de'
temp_files = []
extra_css = 'h1 {font: sans-serif large;}\n.byline {font:monospace;}' extra_css = 'h1 {font: sans-serif large;}\n.byline {font:monospace;}'
conversion_options = { conversion_options = {
@ -32,7 +35,7 @@ class Nzz(BasicNewsRecipe):
,'publisher' : publisher ,'publisher' : publisher
} }
remove_tags = [dict(name='footer')] remove_tags = [dict(name='footer') , dict({'class' : 'fullarticle__related'})]
remove_tags_before = dict(name='article') remove_tags_before = dict(name='article')
remove_tags_after= dict(name='footer') remove_tags_after= dict(name='footer')
@ -41,47 +44,52 @@ class Nzz(BasicNewsRecipe):
baseref = 'https://webpaper.nzz.ch' baseref = 'https://webpaper.nzz.ch'
soup = self.index_to_soup(baseref) soup = self.index_to_soup(baseref)
# print soup.prettify()
articles = {} articles = {}
sections = []
ans = [] ans = []
issue = soup.find("link",rel="prefetch")
issuelist = soup.find(id="issueSelectorList") soup = self.index_to_soup(baseref+issue['href'])
# print soup.prettify()
feeds = issuelist.findAll("a") section = ""
for f in feeds: lastsection = ""
section = f.string
sectionref = baseref + f['href']
ans.append(section)
articlesoup = self.index_to_soup(sectionref)
articlesoup = articlesoup.findAll('article','article')
for a in articlesoup:
artlink = a.find('a')
arthref = baseref + artlink['href']
arthead = a.find('h2')
artcaption = arthead.string
pubdate = strftime('%a, %d %b') pubdate = strftime('%a, %d %b')
if not artcaption is None: articlesoup = soup.findAll("article",{"class" : re.compile(".*fullarticle[ \"].*")})
if not articles.has_key(section): for art in articlesoup:
articles[section] = [] # print art.prettify()
articles[section].append( section=art['data-department']
dict(title=artcaption, url=arthref, date=pubdate, description='', content='')) print "section is "+section
if section != lastsection:
sections.append(section)
articles[section]=[]
lastsection=section
caption = art.find("h2")
self.temp_files.append(PersistentTemporaryFile('_fa.html'))
self.temp_files[-1].write(art.prettify())
self.temp_files[-1].close()
filename = self.temp_files[-1].name
articles[section].append(
dict(title=caption.string,url='file://'+filename, date=pubdate, description='', content=''))
ans = [(key, articles[key]) for key in sections if key in articles]
# pprint.pprint(ans)
ans = [(key, articles[key]) for key in ans if articles.has_key(key)]
return ans return ans
def get_browser(self): def get_browser(self):
br = BasicNewsRecipe.get_browser(self) br = BasicNewsRecipe.get_browser(self)
if self.username is not None and self.password is not None: if self.username is not None and self.password is not None:
br.open('https://cas.nzz.ch/cas/login') br.open('https://webpaper.nzz.ch/login')
br.select_form(nr=0) br.select_form(nr=0)
br['username'] = self.username br['username'] = self.username
br['password'] = self.password br['password'] = self.password
br.submit() br.submit()
return br return br