propagate changes from previous PR to duplicate economist recipe

This commit is contained in:
Kovid Goyal 2024-07-19 19:02:59 +05:30
parent 9851365d8d
commit e4755c3df2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -15,8 +15,6 @@ from calibre.web.feeds.news import BasicNewsRecipe
from html5_parser import parse from html5_parser import parse
from lxml import etree from lxml import etree
# For past editions, set date to, for example, '2020-11-28'.
edition_date = None
use_archive = True use_archive = True
@ -71,7 +69,7 @@ if use_archive:
except Exception: except Exception:
date = data['datePublished'] date = data['datePublished']
dt = datetime.fromisoformat(date[:-1]) + timedelta(seconds=time.timezone) dt = datetime.fromisoformat(date[:-1]) + timedelta(seconds=time.timezone)
dt = dt.strftime('%b %d, %Y, %I:%M %p') dt = dt.strftime('%b %d, %Y %I:%M %p')
if data['dateline'] is None: if data['dateline'] is None:
E(article, 'p', dt, style='color: gray; font-size:small;') E(article, 'p', dt, style='color: gray; font-size:small;')
else: else:
@ -199,6 +197,13 @@ class Economist(BasicNewsRecipe):
# downloaded with connection reset by peer (104) errors. # downloaded with connection reset by peer (104) errors.
delay = 1 delay = 1
recipe_specific_options = {
'date': {
'short': 'The date of the edition to download (YYYY-MM-DD format)',
'long': 'For example, 2024-07-19\nThis seems to work only for a couple of past editions.'
}
}
needs_subscription = False needs_subscription = False
def get_browser(self, *args, **kwargs): def get_browser(self, *args, **kwargs):
@ -209,6 +214,7 @@ class Economist(BasicNewsRecipe):
return br return br
def publication_date(self): def publication_date(self):
edition_date = self.recipe_specific_options.get('date')
if edition_date: if edition_date:
return parse_only_date(edition_date, as_utc=False) return parse_only_date(edition_date, as_utc=False)
url = self.browser.open("https://www.economist.com/printedition").geturl() url = self.browser.open("https://www.economist.com/printedition").geturl()
@ -231,6 +237,7 @@ class Economist(BasicNewsRecipe):
if use_archive: if use_archive:
def parse_index(self): def parse_index(self):
edition_date = self.recipe_specific_options.get('date')
# return self.economist_test_article() # return self.economist_test_article()
# url = 'https://www.economist.com/weeklyedition/archive' # url = 'https://www.economist.com/weeklyedition/archive'
query = { query = {
@ -260,6 +267,7 @@ class Economist(BasicNewsRecipe):
return self.economist_return_index(ans) return self.economist_return_index(ans)
def economist_parse_index(self, raw): def economist_parse_index(self, raw):
edition_date = self.recipe_specific_options.get('date')
if edition_date: if edition_date:
data = json.loads(raw)['data']['section'] data = json.loads(raw)['data']['section']
else: else:
@ -326,6 +334,7 @@ class Economist(BasicNewsRecipe):
self.log.warn('Kindle Output profile being used, reducing image quality to keep file size below amazon email threshold') self.log.warn('Kindle Output profile being used, reducing image quality to keep file size below amazon email threshold')
def parse_index(self): def parse_index(self):
edition_date = self.recipe_specific_options.get('date')
# return self.economist_test_article() # return self.economist_test_article()
if edition_date: if edition_date:
url = 'https://www.economist.com/weeklyedition/' + edition_date url = 'https://www.economist.com/weeklyedition/' + edition_date
@ -416,6 +425,7 @@ class Economist(BasicNewsRecipe):
return raw return raw
def parse_index_from_printedition(self): def parse_index_from_printedition(self):
# return self.economist_test_article() # return self.economist_test_article()
edition_date = self.recipe_specific_options.get('date')
if edition_date: if edition_date:
url = 'https://www.economist.com/weeklyedition/' + edition_date url = 'https://www.economist.com/weeklyedition/' + edition_date
self.timefmt = ' [' + edition_date + ']' self.timefmt = ' [' + edition_date + ']'