From e86be7b3bc6997a5209f83688330ff534978b110 Mon Sep 17 00:00:00 2001 From: Robert Mihaly Date: Tue, 26 Nov 2019 19:48:15 +0100 Subject: [PATCH] Fix Czech local time handling in Denik N recipe Using strftime requires locale change which is not thread safe. Keeping it simple and using a hardcoded list of day and month names, this should work the same way on python 2 and 3 as well. --- recipes/denikn.cz.recipe | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/recipes/denikn.cz.recipe b/recipes/denikn.cz.recipe index 38e6e855d6..f09c7d1586 100644 --- a/recipes/denikn.cz.recipe +++ b/recipes/denikn.cz.recipe @@ -2,25 +2,26 @@ # 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 +from datetime import datetime + + +CZ_DAYS = ['Po', 'Út', 'St', 'Čt', 'Pá', 'So', 'Ne'] +CZ_MONTHS = ['led', 'úno', 'bře', 'dub', 'kvě', 'čen', 'čec', 'srp', 'zář', 'říj', 'lis', 'pro'] def cz_title_time(): """ Helper function to return date with czech locale. + Uses hardcoded lookup table of day and month names as strftime requires + locale change that is not thread safe. """ - - 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 + today = datetime.today() + weekday = CZ_DAYS[today.weekday()] + month = CZ_MONTHS[today.month-1] + return '{weekday}, {day} {month} {year}'.format(weekday=weekday, + day=today.day, + month=month, + year=today.year) class DenikNRecipe(BasicNewsRecipe):