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