Debian Codegraph @

recipes/dnevnik_cro.recipe

raw
1 #!/usr/bin/env python
2
3 __license__ = 'GPL v3'
4 __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
5
6 '''
7 dnevnik.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 DnevnikCro(BasicNewsRecipe):
24 title = 'Dnevnik - Hr'
25 __author__ = 'Darko Miletic'
26 description = 'Vijesti iz Hrvatske'
27 publisher = 'Dnevnik.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 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
40
41 conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': lang, 'pretty_print': True}
42
43 preprocess_regexps = [(re.compile('\u0110'), lambda match: '\u00d0')] # noqa: RUF039
44
45 keep_only_tags = [dict(name='div', attrs={'id': 'article'})]
46
47 remove_tags = [dict(name=['object', 'link', 'embed']), dict(name='div', attrs={'class': 'menu'}), dict(name='div', attrs={'id': 'video'})]
48
49 remove_tags_after = dict(name='div', attrs={'id': 'content'})
50
51 feeds = [('Vijesti', 'http://rss.dnevnik.hr/index.rss')]
52
53 def preprocess_html(self, soup):
54 soup.html['lang'] = self.lang
55 soup.html['dir'] = self.direction
56
57 attribs = [
58 'style',
59 'font',
60 'valign',
61 'colspan',
62 'width',
63 'height',
64 'rowspan',
65 'summary',
66 'align',
67 'cellspacing',
68 'cellpadding',
69 'frames',
70 'rules',
71 'border',
72 ] # noqa: E501
73 for item in soup.body.findAll(name=['table', 'td', 'tr', 'th', 'caption', 'thead', 'tfoot', 'tbody', 'colgroup', 'col']):
74 item.name = 'div'
75 for attrib in attribs:
76 item[attrib] = ''
77 del item[attrib]
78
79 mlang = new_tag(soup, 'meta', [('http-equiv', 'Content-Language'), ('content', self.lang)])
80 mcharset = new_tag(soup, 'meta', [('http-equiv', 'Content-Type'), ('content', 'text/html; charset=UTF-8')])
81 soup.head.insert(0, mlang)
82 soup.head.insert(1, mcharset)
83 return self.adeify_images(soup)