From 13f9c072d28c39122666821794cef07bf4e91173 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 30 Jun 2024 11:44:37 +0530 Subject: [PATCH] Changing locale in a multithreaded program is unsafe after startup If you need to format french day/month names, simple use an array with predefined names and lookup by index. In any case, the fr locale may not actually be available on user systems. --- recipes/liberation.recipe | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/recipes/liberation.recipe b/recipes/liberation.recipe index cf404710f8..ce6f7e8c62 100644 --- a/recipes/liberation.recipe +++ b/recipes/liberation.recipe @@ -2,14 +2,15 @@ liberation.fr ''' -import json, base64, time, locale - -from mechanize import Request +import base64 +import json +import time from datetime import datetime, timedelta -from urllib.parse import quote, urlparse, urlencode +from urllib.parse import quote, urlencode, urlparse from calibre import browser from calibre.web.feeds.news import BasicNewsRecipe +from mechanize import Request def resize(x): @@ -24,7 +25,6 @@ def json_to_html(raw): sub = '

' + data['subheadlines']['basic'] + '

' auth = '

{}

\n' - locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8') dt = datetime.fromisoformat(data['last_updated_date'][:-1]) + timedelta(seconds=time.timezone) dt = dt.strftime('%b %d, %Y, %H:%M') a = [x['name'] for x in data['credits']['by']] @@ -34,7 +34,7 @@ def json_to_html(raw): auth = auth.format(dt) lede = '' - if data['promo_items']['basic'].get('type', '') == 'image': + if data['promo_items']['basic'].get('type', '') == 'image': lede = '
{}
\n'.format( resize(data['promo_items']['basic']['resized_image_urls']), data['promo_items']['basic'].get('caption', '') @@ -107,7 +107,7 @@ class Liberation(BasicNewsRecipe): ] def get_obfuscated_article(self, url): - slug = urlparse(url).path + slug = urlparse(url).path br = browser() b64 = base64.b64decode(self.key) query = {