Debian Codegraph @

recipes/denikn.cz.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
3 from __future__ import absolute_import, division, print_function, unicode_literals
4
5 from datetime import datetime
6
7 from calibre.web.feeds.news import BasicNewsRecipe
8
9 CZ_DAYS = ['Po', 'Út', 'St', 'Čt', 'Pá', 'So', 'Ne']
10 CZ_MONTHS = ['led', 'úno', 'bře', 'dub', 'kvě', 'čen', 'čec', 'srp', 'zář', 'říj', 'lis', 'pro']
11
12
13 def cz_title_time():
14 """
15 Helper function to return date with czech locale.
16 Uses hardcoded lookup table of day and month names as strftime requires
17 locale change that is not thread safe.
18 """
19 today = datetime.today()
20 weekday = CZ_DAYS[today.weekday()]
21 month = CZ_MONTHS[today.month - 1]
22 return '{weekday}, {day} {month} {year}'.format(weekday=weekday, day=today.day, month=month, year=today.year)
23
24
25 class DenikNRecipe(BasicNewsRecipe):
26 """
27 Recipe for the RSS feed of https://denikn.cz/
28 """
29
30 title = 'Deník N'
31 __author__ = 'Robert Mihaly'
32 publisher = 'N Media'
33 description = 'Deník N - Nezávislý český deník'
34
35 # For daily feed
36 oldest_article = 1
37 max_articles_per_feed = 20
38
39 # The default 120 seems too long
40 timeout = 30
41
42 # Custom title used in conversion_options below
43 custom_title = 'Deník N - ' + cz_title_time()
44
45 # Select the feeds to process
46 feeds = [
47 # (u'Vše', 'https://denikn.cz/feed'),
48 ('Česko', 'https://denikn.cz/cesko/feed/'),
49 ('Svět', 'https://denikn.cz/svet/feed'),
50 ('Ekonomika', 'https://denikn.cz/ekonomika/feed'),
51 # (u'Komentáře', 'https://denikn.cz/nazory/feed'),
52 ('Kultura', 'https://denikn.cz/kultura/feed'),
53 ('Věda a technologie', 'https://denikn.cz/veda/feed'),
54 ('Sport', 'https://denikn.cz/sport/feed'),
55 ]
56
57 language = 'cs'
58 cover_url = 'https://denikn.cz/wp-content/themes/dn-2-cz/logo.svg'
59 remove_javascript = True
60
61 publication_type = 'newspaper'
62 tags = 'news'
63
64 # This could be 'optional', but there isn't much content if not subscribed
65 needs_subscription = True
66 # None auto-detects, otherwise 'utf8' could be also used
67 encoding = None
68
69 # Full articles are not embedded
70 use_embedded_content = False
71
72 auto_cleanup = True
73 remove_empty_feeds = True
74
75 ignore_duplicate_articles = {'title', 'url'}
76
77 compress_news_images = True
78 scale_news_images_to_device = True
79
80 resolve_internal_links = True
81
82 # Use gzip transfers
83 handle_gzip = True
84
85 # Add custom title with Czech dates and correctly display publisher
86 conversion_options = {
87 'title': custom_title,
88 # 'comments' : description,
89 # 'tags' : tags,
90 # 'language' : language,
91 'publisher': publisher,
92 # 'authors' : publisher,
93 # 'smarten_punctuation' : True
94 }
95
96 # Handle login here
97 def get_browser(self):
98 br = BasicNewsRecipe.get_browser(self)
99 if self.username is not None and self.password is not None:
100 br.open('https://predplatne.denikn.cz/sign/in/')
101 br.select_form(id='frm-signInForm')
102 br['username'] = self.username
103 br['password'] = self.password
104 br.submit()
105 return br