diff --git a/recipes/denikn.cz.recipe b/recipes/denikn.cz.recipe new file mode 100644 index 0000000000..38e6e855d6 --- /dev/null +++ b/recipes/denikn.cz.recipe @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import unicode_literals, division, absolute_import, print_function +from calibre.web.feeds.news import BasicNewsRecipe +from calibre import strftime +import locale + + +def cz_title_time(): + """ + Helper function to return date with czech locale. + """ + + orig_locale = locale.getlocale(locale.LC_TIME) + try: + locale.setlocale(locale.LC_TIME, 'cs_CZ') + except Exception: + return '' + try: + timestr = strftime('%a, %d %b %Y') + finally: + locale.setlocale(locale.LC_TIME, orig_locale) + return timestr + + +class DenikNRecipe(BasicNewsRecipe): + """ + Recipe for the RSS feed of https://denikn.cz/ + """ + + title = u'Deník N' + __author__ = 'Robert Mihaly' + publisher = u'N Media' + description = u'Deník N - Nezávislý český deník' + + # For daily feed + oldest_article = 1 + max_articles_per_feed = 20 + + # The default 120 seems too long + timeout = 30 + + # Custom title used in conversion_options below + custom_title = u'Deník N - ' + cz_title_time() + + # Select the feeds to process + feeds = [ + # (u'Vše', 'https://denikn.cz/feed'), + (u'Česko', 'https://denikn.cz/cesko/feed/'), + (u'Svět', 'https://denikn.cz/svet/feed'), + (u'Ekonomika', 'https://denikn.cz/ekonomika/feed'), + # (u'Komentáře', 'https://denikn.cz/nazory/feed'), + (u'Kultura', 'https://denikn.cz/kultura/feed'), + (u'Věda a technologie', 'https://denikn.cz/veda/feed'), + (u'Sport', 'https://denikn.cz/sport/feed'), + ] + + language = 'cs' + cover_url = 'https://denikn.cz/wp-content/themes/dn-2-cz/logo.svg' + remove_javascript = True + + publication_type = 'newspaper' + tags = 'news' + + # This could be 'optional', but there isn't much content if not subscribed + needs_subscription = True + # None auto-detects, otherwise 'utf8' could be also used + encoding = None + + # Full articles are not embedded + use_embedded_content = False + + auto_cleanup = True + remove_empty_feeds = True + + ignore_duplicate_articles = {'title', 'url'} + + compress_news_images = True + scale_news_images_to_device = True + + resolve_internal_links = True + + # Use gzip transfers + handle_gzip = True + + # Add custom title with Czech dates and correctly display publisher + conversion_options = { + 'title' : custom_title, + # 'comments' : description, + # 'tags' : tags, + # 'language' : language, + 'publisher' : publisher, + # 'authors' : publisher, + # 'smarten_punctuation' : True + } + + # Handle login here + def get_browser(self): + br = BasicNewsRecipe.get_browser(self) + if self.username is not None and self.password is not None: + br.open('https://predplatne.denikn.cz/sign/in/') + br.select_form(id='frm-signInForm') + br['username'] = self.username + br['password'] = self.password + br.submit() + return br diff --git a/recipes/icons/denikn.cz.png b/recipes/icons/denikn.cz.png new file mode 100644 index 0000000000..7ed28e2c5a Binary files /dev/null and b/recipes/icons/denikn.cz.png differ