1#!/usr/local/bin/python3.8
2
3__license__ = 'GPL v3'
4__copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
5
6'''
7nacional.hr
8'''
9
10import re
11from calibre.web.feeds.recipes import BasicNewsRecipe
12from calibre.ebooks.BeautifulSoup import Tag
13
14
15def new_tag(soup, name, attrs=()):
16    impl = getattr(soup, 'new_tag', None)
17    if impl is not None:
18        return impl(name, attrs=dict(attrs))
19    return Tag(soup, name, attrs=attrs or None)
20
21
22class NacionalCro(BasicNewsRecipe):
23    title = 'Nacional - Hr'
24    __author__ = 'Darko Miletic'
25    description = "news from Croatia"
26    publisher = 'Nacional.hr'
27    category = 'news, politics, Croatia'
28    oldest_article = 2
29    max_articles_per_feed = 100
30    delay = 4
31    no_stylesheets = True
32    encoding = 'utf-8'
33    use_embedded_content = False
34    language = 'hr'
35
36    lang = 'hr-HR'
37    direction = 'ltr'
38
39    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}'  # noqa
40
41    conversion_options = {
42        'comment': description, 'tags': category, 'publisher': publisher, 'language': lang, 'pretty_print': True
43    }
44
45    preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
46
47    remove_tags = [dict(name=['object', 'link', 'embed'])]
48
49    feeds = [(u'Najnovije Vijesti', u'http://www.nacional.hr/rss')]
50
51    def preprocess_html(self, soup):
52        soup.html['lang'] = self.lang
53        soup.html['dir'] = self.direction
54        mlang = new_tag(soup, 'meta', [
55                    ("http-equiv", "Content-Language"), ("content", self.lang)])
56        mcharset = new_tag(soup, 'meta', [
57                       ("http-equiv", "Content-Type"), ("content", "text/html; charset=UTF-8")])
58        soup.head.insert(0, mlang)
59        soup.head.insert(1, mcharset)
60        for item in soup.findAll(style=True):
61            del item['style']
62        return soup
63
64    def print_version(self, url):
65        rest, sep, disc = url.rpartition('/')
66        return rest.replace('/clanak/', '/clanak/print/')
67