This commit is contained in:
Kovid Goyal 2024-07-19 19:02:03 +05:30
commit 9851365d8d
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 lxml import etree
# For past editions, set date to, for example, '2020-11-28'.
edition_date = None
use_archive = True
@ -71,7 +69,7 @@ if use_archive:
except Exception:
date = data['datePublished']
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:
E(article, 'p', dt, style='color: gray; font-size:small;')
else:
@ -199,6 +197,13 @@ class Economist(BasicNewsRecipe):
# downloaded with connection reset by peer (104) errors.
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
def get_browser(self, *args, **kwargs):
@ -209,6 +214,7 @@ class Economist(BasicNewsRecipe):
return br
def publication_date(self):
edition_date = self.recipe_specific_options.get('date')
if edition_date:
return parse_only_date(edition_date, as_utc=False)
url = self.browser.open("https://www.economist.com/printedition").geturl()
@ -231,6 +237,7 @@ class Economist(BasicNewsRecipe):
if use_archive:
def parse_index(self):
edition_date = self.recipe_specific_options.get('date')
# return self.economist_test_article()
# url = 'https://www.economist.com/weeklyedition/archive'
query = {
@ -260,6 +267,7 @@ class Economist(BasicNewsRecipe):
return self.economist_return_index(ans)
def economist_parse_index(self, raw):
edition_date = self.recipe_specific_options.get('date')
if edition_date:
data = json.loads(raw)['data']['section']
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')
def parse_index(self):
edition_date = self.recipe_specific_options.get('date')
# return self.economist_test_article()
if edition_date:
url = 'https://www.economist.com/weeklyedition/' + edition_date
@ -416,6 +425,7 @@ class Economist(BasicNewsRecipe):
return raw
def parse_index_from_printedition(self):
# return self.economist_test_article()
edition_date = self.recipe_specific_options.get('date')
if edition_date:
url = 'https://www.economist.com/weeklyedition/' + edition_date
self.timefmt = ' [' + edition_date + ']'