Debian Codegraph @

recipes/vreme.recipe

raw
1 __license__ = 'GPL v3'
2 __copyright__ = '2008-2012, Darko Miletic <darko.miletic at gmail.com>'
3 '''
4 vreme.com
5 '''
6
7 import re
8
9 from calibre import strftime
10 from calibre.web.feeds.news import BasicNewsRecipe
11
12
13 class Vreme(BasicNewsRecipe):
14 title = 'Vreme'
15 __author__ = 'Darko Miletic'
16 description = 'Politicki Nedeljnik Srbije'
17 publisher = 'NP Vreme d.o.o.'
18 category = 'news, politics, Serbia'
19 delay = 1
20 no_stylesheets = True
21 needs_subscription = True
22 INDEX = 'http://www.vreme.com'
23 LOGIN = 'http://www.vreme.com/account/login.php?url=%2F'
24 use_embedded_content = False
25 encoding = 'utf-8'
26 language = 'sr'
27 publication_type = 'magazine'
28 masthead_url = 'http://www.vreme.com/g/vreme-logo.gif'
29 extra_css = '''
30 @font-face {font-family: "serif1";src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)}
31 @font-face {font-family: "sans1";src:url(res:///opt/sony/ebook/FONT/tt0003m_.ttf)}
32 body{font-family: serif1, serif}
33 .article_description{font-family: serif1, serif}
34 .column-heading2{font-family: sans1, sans-serif; font-size: large}
35 .column-heading1{font-family: sans1, sans-serif; font-size: x-large}
36 .column-normal{font-family: sans1, sans-serif; font-size: medium}
37 .large{font-family: sans1, sans-serif; font-size: large}
38 '''
39
40 conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language, 'linearize_tables': True}
41
42 preprocess_regexps = [(re.compile('\u0110'), lambda match: '\u00d0')] # noqa: RUF039
43 remove_tags_before = dict(attrs={'class': 'toc-heading'})
44 remove_tags_after = dict(attrs={'class': 'footer'})
45
46 def get_browser(self):
47 br = BasicNewsRecipe.get_browser(self)
48 if self.username is not None and self.password is not None:
49 br.open(self.LOGIN)
50 br.select_form(name='f')
51 br['username'] = self.username
52 br['password'] = self.password
53 br.submit()
54 return br
55
56 def parse_index(self):
57 articles = []
58 soup = self.index_to_soup(self.INDEX)
59 cover_item = soup.find('div', attrs={'id': 'najava'})
60 if cover_item:
61 self.cover_url = self.INDEX + cover_item.img['src']
62 for item in soup.findAll(['h3', 'h4']):
63 description = ''
64 title_prefix = ''
65 feed_link = item.find('a', href=True)
66 if feed_link and (feed_link['href'].startswith('cms/view.php') or feed_link['href'].startswith('/cms/view.php')):
67 if feed_link['href'].startswith('cms/view.php'):
68 url = self.INDEX + '/' + feed_link['href']
69 else:
70 url = self.INDEX + feed_link['href']
71 title = title_prefix + self.tag_to_string(feed_link)
72 date = strftime(self.timefmt)
73 articles.append({'title': title, 'date': date, 'url': url, 'description': description})
74 return [('Nedeljnik Vreme', articles)]
75
76 remove_tags = [dict(name=['object', 'link']), dict(name='table', attrs={'xclass': 'image'})]
77
78 def print_version(self, url):
79 return url + '&print=yes'