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