Debian Codegraph @

recipes/gazeta_pl_warszawa.recipe

raw
1 #!/usr/bin/env python
2
3 __license__ = 'GPL v3'
4 __author__ = 'teepel <[email protected]> based on GW from fenuks'
5
6 '''
7 warszawa.gazeta.pl
8 '''
9
10 import re
11
12 from calibre.ebooks.BeautifulSoup import Comment
13 from calibre.web.feeds.news import BasicNewsRecipe
14
15
16 class gw_wawa(BasicNewsRecipe):
17 title = 'Gazeta Wyborcza Warszawa'
18 __author__ = 'teepel <[email protected]> based on GW from fenuks'
19 language = 'pl'
20 description = 'Wiadomości z Warszawy na portalu Gazeta.pl.'
21 category = 'newspaper'
22 publication_type = 'newspaper'
23 masthead_url = 'http://bi.gazeta.pl/im/3/4089/m4089863.gif'
24 INDEX = 'http://warszawa.gazeta.pl'
25 cover_url = 'http://bi.gazeta.pl/i/hp/hp2009/logo.gif'
26 remove_empty_feeds = True
27 oldest_article = 3
28 max_articles_per_feed = 100
29 remove_javascript = True
30 no_stylesheets = True
31 use_embedded_content = False
32 ignore_duplicate_articles = {'title', 'url'}
33
34 # rules for gazeta.pl
35 preprocess_regexps = [(re.compile('<b>Czytaj więcej</b>.*', re.DOTALL), lambda m: '</body>')] # noqa: RUF039
36 keep_only_tags = [dict(id='gazeta_article')]
37 remove_tags = [dict(id=['gazeta_article_tools', 'gazeta_article_miniatures']), dict(attrs={'class': ['mod mod_sociallist', 'c0', 'fb', 'voteNeedLogin']})]
38 remove_tags_after = dict(id='gazeta_article_body')
39
40 feeds = [('Wiadomości', 'http://rss.gazeta.pl/pub/rss/warszawa.xml')]
41
42 def print_version(self, url):
43 if 'feedsportal.com' in url:
44 s = url.rpartition('gazeta0Bpl')
45 u = s[2]
46 if not s[0]:
47 u = url.rpartition('wyborcza0Bpl')[2]
48 u = u.replace('/l/', '/')
49 u = u.replace('/ia1.htm', '')
50 u = u.replace('/story01.htm', '')
51 u = u.replace('0C', '/')
52 u = u.replace('A', '')
53 u = u.replace('0E', '-')
54 u = u.replace('0H', ',')
55 u = u.replace('0I', '_')
56 u = u.replace('0B', '.')
57 u = self.INDEX + u
58 return u
59 else:
60 return url
61
62 def preprocess_html(self, soup):
63 tag = soup.find(id='Str')
64 if soup.find(attrs={'class': 'piano_btn_1'}):
65 return None
66 elif tag and tag.findAll('a'):
67 self.append_page(soup, soup.body)
68 return soup
69
70 def append_page(self, soup, appendtag):
71 tag = soup.find('div', attrs={'id': 'Str'})
72 try:
73 baseurl = soup.find(name='meta', attrs={'property': 'og:url'})['content']
74 except Exception:
75 return 1
76 link = tag.findAll('a')[-1]
77 while link:
78 soup2 = self.index_to_soup(baseurl + link['href'])
79 link = soup2.find('div', attrs={'id': 'Str'}).findAll('a')[-1]
80 if 'następne' not in link.string:
81 link = ''
82 pagetext = soup2.find(id='artykul')
83 comments = pagetext.findAll(text=lambda text: isinstance(text, Comment))
84 for comment in comments:
85 comment.extract()
86 pos = len(appendtag.contents)
87 appendtag.insert(pos, pagetext)
88 tag.extract()
89
90 def image_url_processor(self, baseurl, url):
91 if url.startswith(' '):
92 return url.strip()
93 else:
94 return url