mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Update NZZ
This commit is contained in:
parent
d51a0be334
commit
480cc884fe
@ -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>'
|
||||||
|
|
||||||
@ -25,11 +24,11 @@ class Nzz(BasicNewsRecipe):
|
|||||||
.artikel h3,.artikel h4,.bildLegende,.question,.autor{font-family: Arial,Verdana,Helvetica,sans-serif}
|
.artikel h3,.artikel h4,.bildLegende,.question,.autor{font-family: Arial,Verdana,Helvetica,sans-serif}
|
||||||
.bildLegende{font-size: small}
|
.bildLegende{font-size: small}
|
||||||
.autor{font-size: 0.9375em; color: #666666}
|
.autor{font-size: 0.9375em; color: #666666}
|
||||||
.quote{font-size: large !important;
|
.quote{font-size: large !important;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
font-weight: normal !important;
|
font-weight: normal !important;
|
||||||
border-bottom: 1px dotted #BFBFBF;
|
border-bottom: 1px dotted #BFBFBF;
|
||||||
border-top: 1px dotted #BFBFBF;
|
border-top: 1px dotted #BFBFBF;
|
||||||
line-height: 1.25em}
|
line-height: 1.25em}
|
||||||
.quelle{color: #666666; font-style: italic; white-space: nowrap}
|
.quelle{color: #666666; font-style: italic; white-space: nowrap}
|
||||||
"""
|
"""
|
||||||
@ -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')
|
||||||
|
@ -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()
|
||||||
|
section = ""
|
||||||
|
lastsection = ""
|
||||||
|
pubdate = strftime('%a, %d %b')
|
||||||
|
|
||||||
feeds = issuelist.findAll("a")
|
articlesoup = soup.findAll("article",{"class" : re.compile(".*fullarticle[ \"].*")})
|
||||||
for f in feeds:
|
for art in articlesoup:
|
||||||
section = f.string
|
# print art.prettify()
|
||||||
sectionref = baseref + f['href']
|
section=art['data-department']
|
||||||
|
print "section is "+section
|
||||||
|
|
||||||
ans.append(section)
|
if section != lastsection:
|
||||||
|
sections.append(section)
|
||||||
|
articles[section]=[]
|
||||||
|
lastsection=section
|
||||||
|
|
||||||
articlesoup = self.index_to_soup(sectionref)
|
caption = art.find("h2")
|
||||||
|
|
||||||
articlesoup = articlesoup.findAll('article','article')
|
self.temp_files.append(PersistentTemporaryFile('_fa.html'))
|
||||||
for a in articlesoup:
|
self.temp_files[-1].write(art.prettify())
|
||||||
artlink = a.find('a')
|
self.temp_files[-1].close()
|
||||||
|
filename = self.temp_files[-1].name
|
||||||
|
|
||||||
arthref = baseref + artlink['href']
|
articles[section].append(
|
||||||
arthead = a.find('h2')
|
dict(title=caption.string,url='file://'+filename, date=pubdate, description='', content=''))
|
||||||
artcaption = arthead.string
|
|
||||||
|
|
||||||
pubdate = strftime('%a, %d %b')
|
ans = [(key, articles[key]) for key in sections if key in articles]
|
||||||
|
|
||||||
if not artcaption is None:
|
# pprint.pprint(ans)
|
||||||
if not articles.has_key(section):
|
|
||||||
articles[section] = []
|
|
||||||
articles[section].append(
|
|
||||||
dict(title=artcaption, url=arthref, date=pubdate, description='', content=''))
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user