1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
5
__copyright__ = '2011, Piotr Kontek, piotr.kontek@gmail.com \
6
2013-2014, Tomasz Długosz, tomek3d@gmail.com'
8
from calibre.web.feeds.news import BasicNewsRecipe
12
class GN(BasicNewsRecipe):
13
__author__ = 'Piotr Kontek, Tomasz Długosz'
14
title = u'Gość Niedzielny - pełny numer'
15
publisher = 'Wydawnictwo Kurii Metropolitalnej w Katowicach'
16
description = 'Ogólnopolski tygodnik katolicki - pełny numer sprzed 4 tygodni'
20
remove_javascript = True
22
def find_last_issue(self):
23
raw = self.index_to_soup('http://gosc.pl/wyszukaj/wydania/3.Gosc-Niedzielny/', raw=True)
24
doc = html.fromstring(raw)
25
page = doc.xpath('//div[@class="c"]//div[@class="search-result"]/div[1]/div[2]/h1//a/@href')
27
if time.strftime("%w") in ['3','4']:
32
def parse_index(self):
33
soup = self.index_to_soup('http://gosc.pl' + self.find_last_issue())
34
self.cover_url = 'http://www.gosc.pl' + soup.find('div',attrs={'class':'fl-w100 release-wp'}).findAll('a')[-4].contents[0]['src']
38
a = soup.find('div',attrs={'class':'release-wp-b'})
41
{'title' : self.tag_to_string(art),
42
'url' : 'http://www.gosc.pl' + art['href'],
43
'description' : self.tag_to_string(a.find('p',attrs={'class':'b lead'}))
45
feeds.append((u'Wstępniak',articles))
46
enlisted.append(articles[0].get('url'))
48
for addr in soup.findAll('a',attrs={'href':re.compile('kategoria')}):
49
if addr.string != u'wszystkie artyku\u0142y z tej kategorii \xbb':
50
main_block = self.index_to_soup('http://www.gosc.pl' + addr['href'])
51
articles = list(self.find_articles(main_block))
54
feeds.append((section, articles))
55
enlisted.extend(list(article.get('url') for article in articles))
56
# not assigned content:
60
soup = self.index_to_soup('http://gosc.pl' + self.find_last_issue().replace('przeglad','wszystko') + '/' + str(page))
61
articles = list(self.find_articles(soup))
62
not_assigned.extend([x for x in articles if x.get('url') not in enlisted])
64
pages = soup.find('span', attrs={'class':'pgr_nrs'})
65
if str(page) not in [self.tag_to_string(x)[1] for x in pages.findAll('a')]:
68
feeds.insert(1,(u'Nieprzypisane', not_assigned))
71
def find_articles(self, main_block):
72
for a in main_block.findAll('div', attrs={'class':['prev_doc2', 'sr-document']}):
75
'title' : self.tag_to_string(art),
76
'url' : 'http://www.gosc.pl' + art['href'],
77
'date' : self.tag_to_string(a.find('p', attrs={'class':'sr-date'})),
78
'description' : self.tag_to_string(a.find('p', attrs={'class':'sr-lead'}))
81
def append_page(self, soup, appendtag):
82
chpage= appendtag.find(attrs={'class':'pgr_nrs'})
84
for page in chpage.findAll('a'):
85
soup2 = self.index_to_soup('http://gosc.pl' + page['href'])
86
pagetext = soup2.find(attrs={'class':'intextAd'})
87
pos = len(appendtag.contents)
88
appendtag.insert(pos, pagetext)
90
def preprocess_html(self, soup):
91
self.append_page(soup, soup.body)
92
r = soup.find(attrs={'class':'lightbox'})
94
r.contents[0]['src'] = r['href']
97
def postprocess_html(self, soup, first_fetch):
98
for r in soup.findAll(attrs={'class':'pgr'}):
100
for r in soup.findAll(attrs={'class':['di_dr', 'doc_image']}):
102
for r in soup.findAll(attrs={'class':'cm-i-a'}):
103
r.replaceWith('<div style="clear:both"></div>' + r.prettify() + '<div style="clear:both"></div>')
107
dict(name='div', attrs={'class':'cf txt'})
111
dict(name='p', attrs={'class':['r tr', 'l l-2', 'wykop', 'tags']}),
112
dict(name='div', attrs={'class':['doc_actions', 'cf', 'fr1_cl']}),
113
dict(name='div', attrs={'id':'vote'}),
115
dict(name='a', attrs={'class':'img_enlarge'})
120
p.limiter {font-size:150%; font-weight: bold}
121
span.cm-i-a {text-transform:uppercase;font-size:50%}
122
span.cm-i-p {font-style:italic; font-size:70%;text-align:right}