mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update tyzden
Merge branch 'master' of https://github.com/rakyi/calibre
This commit is contained in:
commit
6a891948d3
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
#
|
#
|
||||||
# Copyright 2014 Martin Račák <martin.racak@riseup.net>
|
# Copyright 2014 - 2015 Martin Račák <rakyi@riseup.net>
|
||||||
# Copyright 2011 Miroslav Vasko <zemiak@gmail.com>
|
# Copyright 2011 Miroslav Vasko <zemiak@gmail.com>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@ -18,7 +18,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2014 Martin Račák <martin.racak@riseup.net>, 2011 Miroslav Vasko <zemiak@gmail.com>'
|
__copyright__ = '2014 - 2015 Martin Račák <martin.racak@riseup.net>, 2011 Miroslav Vasko <zemiak@gmail.com>'
|
||||||
|
|
||||||
'''
|
'''
|
||||||
.týždeň - iný pohľad na spoločnosť
|
.týždeň - iný pohľad na spoločnosť
|
||||||
@ -27,7 +27,6 @@ __copyright__ = '2014 Martin Račák <martin.racak@riseup.net>, 2011 Miroslav Va
|
|||||||
import re
|
import re
|
||||||
from calibre import strftime
|
from calibre import strftime
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
class Tyzden(BasicNewsRecipe):
|
class Tyzden(BasicNewsRecipe):
|
||||||
title = u'týždeň'
|
title = u'týždeň'
|
||||||
@ -50,50 +49,40 @@ class Tyzden(BasicNewsRecipe):
|
|||||||
br.submit()
|
br.submit()
|
||||||
return br
|
return br
|
||||||
|
|
||||||
today = date.today()
|
base_url = 'http://www.tyzden.sk/casopis.html'
|
||||||
iso = today.isocalendar()
|
|
||||||
year = iso[0]
|
|
||||||
weeknum = iso[1]
|
|
||||||
|
|
||||||
base_url_path = 'http://www.tyzden.sk/casopis/' + str(year) + '/' + str(weeknum)
|
|
||||||
base_url = base_url_path + '.html'
|
|
||||||
|
|
||||||
keep_only_tags = []
|
keep_only_tags = []
|
||||||
keep_only_tags.append(dict(name='div', attrs={'class': 'text_area top_nofoto'}))
|
keep_only_tags.append(dict(name='div', attrs={'class': 'text_area top_nofoto'}))
|
||||||
keep_only_tags.append(dict(name='div', attrs={'class': 'text_block'}))
|
keep_only_tags.append(dict(name='div', attrs={'class': 'text_block'}))
|
||||||
|
|
||||||
remove_tags_after = [dict(name='div', attrs={'class': 'text_block'})]
|
|
||||||
|
|
||||||
extra_css = '.top_nofoto h1 { text-align: left; font-size: 1.7em; }'
|
|
||||||
|
|
||||||
def find_sections(self):
|
def find_sections(self):
|
||||||
soup = self.index_to_soup(self.base_url)
|
soup = self.index_to_soup(self.base_url)
|
||||||
# find cover pic
|
# Use only the impotant part of page
|
||||||
imgdiv = soup.find('div', attrs={'class': 'foto'})
|
content = soup.find('div', 'top')
|
||||||
if imgdiv is not None:
|
content.extract()
|
||||||
img = imgdiv.find('img')
|
|
||||||
if img is not None:
|
|
||||||
self.cover_url = 'http://www.tyzden.sk/' + img['src']
|
|
||||||
# end find cover pic
|
|
||||||
|
|
||||||
for s in soup.findAll('a', attrs={'href': re.compile(r'rubrika/.*')}):
|
# Find cover pic
|
||||||
yield (self.tag_to_string(s), s)
|
img = content.find('div', 'foto').img
|
||||||
|
if img is not None:
|
||||||
|
self.cover_url = 'http://www.tyzden.sk/' + img['src']
|
||||||
|
|
||||||
|
for section in content.findAll('a', {'href': re.compile(r'rubrika/.*')}):
|
||||||
|
yield (self.tag_to_string(section), section)
|
||||||
|
|
||||||
def find_articles(self, soup):
|
def find_articles(self, soup):
|
||||||
for art in soup.findAllNext('a'):
|
for article in soup.findAllNext('a'):
|
||||||
if (not art['href'].startswith('casopis/' + str(self.year) + '/' + str(self.weeknum) + '/')):
|
if (not article['href'].startswith('casopis/')):
|
||||||
break
|
break
|
||||||
|
|
||||||
url = art['href']
|
|
||||||
title = self.tag_to_string(art)
|
|
||||||
yield {
|
yield {
|
||||||
'title': title, 'url':self.base_url_path + '/' + url,
|
'title': self.tag_to_string(article),
|
||||||
'date' : strftime(' %a, %d %b'),
|
'url': self.base_url + '/' + article['href'],
|
||||||
|
'date': strftime(' %a, %d %b'),
|
||||||
}
|
}
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
feeds = []
|
feeds = []
|
||||||
for title, soup in self.find_sections():
|
for title, section in self.find_sections():
|
||||||
feeds.append((title, list(self.find_articles(soup))))
|
feeds.append((title, list(self.find_articles(section))))
|
||||||
|
|
||||||
return feeds
|
return feeds
|
||||||
|
Loading…
x
Reference in New Issue
Block a user