Debian Codegraph @

recipes/novilist_novine_hr.recipe

raw
1 __license__ = 'GPL v3'
2 __copyright__ = '2012, Darko Miletic <darko.miletic at gmail.com>'
3 '''
4 novine.novilist.hr
5 '''
6
7 import re
8
9 from calibre import strftime
10 from calibre.web.feeds.news import BasicNewsRecipe
11
12
13 class NoviList_hr(BasicNewsRecipe):
14 title = 'Novi List'
15 __author__ = 'Darko Miletic'
16 description = 'Vijesti iz Hrvatske'
17 publisher = 'NOVI LIST d.d.'
18 category = 'Novi list, politika, hrvatski dnevnik, Novine, Hrvatska, Croatia, News, newspaper, Hrvatski,Primorje, dnevni list, Rijeka'
19 oldest_article = 2
20 max_articles_per_feed = 200
21 no_stylesheets = True
22 encoding = 'cp1250'
23 use_embedded_content = False
24 language = 'hr'
25 remove_empty_feeds = True
26 publication_type = 'newspaper'
27 needs_subscription = True
28 masthead_url = 'http://novine.novilist.hr/images/system/novilist-logo.jpg'
29 index = 'http://novine.novilist.hr/'
30 extra_css = '''
31 @font-face {font-family: "sans1";src:url(res:///opt/sony/ebook/FONT/tt0003m_.ttf)}
32 body{font-family: Geneva,Arial,Helvetica,Swiss,sans1,sans-serif }
33 img{display:block; margin-bottom: 0.4em; margin-top: 0.4em}
34 .nadnaslov,.podnaslov{font-size: small; display: block; margin-bottom: 1em}
35 .naslov{font-size: x-large; color: maroon; font-weight: bold; display: block; margin-bottom: 1em;}
36 p{display: block}
37 '''
38
39 preprocess_regexps = [(re.compile('\u0110'), lambda match: '\u00d0')] # noqa: RUF039
40
41 conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language, 'linearize_tables': True}
42
43 keep_only_tags = [dict(name='td', attrs={'class': ['nadnaslov', 'naslov', 'podnaslov']}), dict(name='font', attrs={'face': 'Geneva,Arial,Helvetica,Swiss'})]
44
45 remove_tags = [dict(name=['meta', 'link', 'iframe', 'embed', 'object'])]
46 remove_attributes = ['border', 'lang', 'size', 'face', 'bgcolor']
47
48 def get_browser(self):
49 br = BasicNewsRecipe.get_browser(self)
50 if self.username is not None and self.password is not None:
51 br.open(self.index + 'loginnow.asp')
52 br.select_form(nr=0)
53 br['username'] = self.username
54 br['password'] = self.password
55 br.submit()
56 return br
57
58 def parse_index(self):
59 articles = []
60 count = 0
61 soup = self.index_to_soup(self.index)
62 # cover url
63 for alink in soup.findAll('a'):
64 if alink['href'].startswith('images/clanci/DOC_'):
65 self.cover_url = self.index + alink['href']
66 # feeds
67 for item in soup.findAll('td', attrs={'class': 'tocrubrika'}):
68 count = count + 1
69 if self.test and count > 2:
70 return articles
71 aitem = item.a
72 section = self.tag_to_string(aitem)
73 feedlink = self.index + aitem['href']
74 feedpage = self.index_to_soup(feedlink)
75 self.report_progress(0, _('Fetching feed') + ' %s...' % (section))
76 inarts = []
77 for alink in feedpage.findAll('a', attrs={'class': 'naslovlinkdesno'}):
78 url = self.index + alink['href']
79 inarts.append({'title': self.tag_to_string(alink), 'date': strftime(self.timefmt), 'url': url, 'description': ''})
80 if self.remove_empty_feeds:
81 if inarts:
82 articles.append((section, inarts))
83 else:
84 articles.append((section, inarts))
85 return articles
86
87 def print_version(self, url):
88 return url.replace('?WCI=Rubrike&', '?WCI=Pretrazivac&')