1#!/usr/local/bin/python3.8
2
3__license__ = 'GPL v3'
4__copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
5
6'''
7republika.co.yu
8'''
9
10import re
11from calibre.web.feeds.news import BasicNewsRecipe
12
13
14class Republika(BasicNewsRecipe):
15    title = 'Republika'
16    __author__ = 'Darko Miletic'
17    description = 'Glasilo gradjanskog samooslobadjanja. Protiv stihije straha, mrznje i nasilja'
18    publisher = ' Zadruga Res Publica'
19    category = 'news, politics, Serbia'
20    language = 'sr'
21
22    lang = 'sr-Latn-RS'
23    oldest_article = 2
24    max_articles_per_feed = 100
25    no_stylesheets = True
26    encoding = 'cp1250'
27    use_embedded_content = False
28    INDEX = u'http://www.republika.co.yu/'
29    extra_css = ' @font-face {font-family: "serif1"; src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)} body{font-family: serif1, serif} .article_description{font-family: serif1, serif} .naslov{font-size: x-large; font-weight: bold} .autor{font-size: small; font-weight: bold} '  # noqa
30
31    conversion_options = {
32        'comment': description, 'tags': category, 'publisher': publisher, 'language': lang, 'pretty_print': True
33    }
34
35    preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
36
37    keep_only_tags = [dict(attrs={'class': 'naslov'}), dict(attrs={'class': 'text1'})
38                      ]
39
40    remove_tags = [dict(name=['object', 'link', 'iframe', 'base', 'img'])]
41
42    feeds = [(u'Svi clanci', INDEX)]
43
44    def preprocess_html(self, soup):
45        attribs = ['style', 'font', 'valign', 'colspan', 'width', 'height', 'rowspan', 'summary', 'align', 'cellspacing', 'cellpadding', 'frames', 'rules', 'border' ]  # noqa
46        for item in soup.body.findAll(name=['table', 'td', 'tr', 'th', 'caption', 'thead', 'tfoot', 'tbody', 'colgroup', 'col']):
47            item.name = 'div'
48            for attrib in attribs:
49                item[attrib] = ''
50                del item[attrib]
51        return soup
52
53    def parse_index(self):
54        totalfeeds = []
55        lfeeds = self.get_feeds()
56        for feedobj in lfeeds:
57            feedtitle, feedurl = feedobj
58            self.report_progress(0, _('Fetching feed') + ' %s...' %
59                                 (feedtitle if feedtitle else feedurl))
60            articles = []
61            soup = self.index_to_soup(feedurl)
62            for item in soup.findAll('a', attrs={'class': 'naslovLink'}):
63                url = item['href']
64                title = self.tag_to_string(item)
65                articles.append({
66                    'title': title, 'date': '', 'url': url, 'description': ''
67                })
68            totalfeeds.append((feedtitle, articles))
69        return totalfeeds
70