diff --git a/recipes/economist.recipe b/recipes/economist.recipe index f4f2e644b4..cf47a8fda1 100644 --- a/recipes/economist.recipe +++ b/recipes/economist.recipe @@ -268,13 +268,21 @@ class Economist(BasicNewsRecipe): dt = dt.strftime('%b %d, %Y') self.timefmt = ' [' + dt + ']' # get local issue cover, title - region = json.loads(self.index_to_soup('https://geolocation-db.com/json', raw=True))['country_code'] + try: + region = json.loads(self.index_to_soup('https://geolocation-db.com/json', raw=True))['country_code'] + except Exception: + region = '' for cov in data['image']['cover']: if region in cov['regionsAllowed']: self.description = cov['headline'] - self.cover_url = cov['url']['canonical'].replace('economist.com/', + self.cover_url = cov['url']['canonical'].replace('economist.com/', 'economist.com/cdn-cgi/image/width=960,quality=80,format=auto/') - self.log('Got cover:', self.cover_url, '\n', self.description) + break + else: + self.description = data['image']['cover'][0]['headline'] + self.cover_url = data['image']['cover'][0]['url']['canonical'].replace('economist.com/', + 'economist.com/cdn-cgi/image/width=960,quality=80,format=auto/') + self.log('Got cover:', self.cover_url, '\n', self.description) feeds_dict = defaultdict(list) for part in safe_dict(data, "hasPart", "parts"): @@ -302,7 +310,7 @@ class Economist(BasicNewsRecipe): def preprocess_html(self, soup): for img in soup.findAll('img', src=True): - img['src'] = img['src'].replace('economist.com/', + img['src'] = img['src'].replace('economist.com/', 'economist.com/cdn-cgi/image/width=600,quality=80,format=auto/') return soup diff --git a/recipes/economist_free.recipe b/recipes/economist_free.recipe index f4f2e644b4..cf47a8fda1 100644 --- a/recipes/economist_free.recipe +++ b/recipes/economist_free.recipe @@ -268,13 +268,21 @@ class Economist(BasicNewsRecipe): dt = dt.strftime('%b %d, %Y') self.timefmt = ' [' + dt + ']' # get local issue cover, title - region = json.loads(self.index_to_soup('https://geolocation-db.com/json', raw=True))['country_code'] + try: + region = json.loads(self.index_to_soup('https://geolocation-db.com/json', raw=True))['country_code'] + except Exception: + region = '' for cov in data['image']['cover']: if region in cov['regionsAllowed']: self.description = cov['headline'] - self.cover_url = cov['url']['canonical'].replace('economist.com/', + self.cover_url = cov['url']['canonical'].replace('economist.com/', 'economist.com/cdn-cgi/image/width=960,quality=80,format=auto/') - self.log('Got cover:', self.cover_url, '\n', self.description) + break + else: + self.description = data['image']['cover'][0]['headline'] + self.cover_url = data['image']['cover'][0]['url']['canonical'].replace('economist.com/', + 'economist.com/cdn-cgi/image/width=960,quality=80,format=auto/') + self.log('Got cover:', self.cover_url, '\n', self.description) feeds_dict = defaultdict(list) for part in safe_dict(data, "hasPart", "parts"): @@ -302,7 +310,7 @@ class Economist(BasicNewsRecipe): def preprocess_html(self, soup): for img in soup.findAll('img', src=True): - img['src'] = img['src'].replace('economist.com/', + img['src'] = img['src'].replace('economist.com/', 'economist.com/cdn-cgi/image/width=600,quality=80,format=auto/') return soup diff --git a/recipes/economist_world_ahead.recipe b/recipes/economist_world_ahead.recipe index 6e70499cd5..f2923a10f1 100644 --- a/recipes/economist_world_ahead.recipe +++ b/recipes/economist_world_ahead.recipe @@ -10,7 +10,6 @@ from urllib.parse import quote, urlencode from calibre import replace_entities from calibre.ebooks.BeautifulSoup import NavigableString, Tag from calibre.ptempfile import PersistentTemporaryFile -from calibre.utils.date import parse_only_date from calibre.web.feeds.news import BasicNewsRecipe from html5_parser import parse from lxml import etree @@ -270,7 +269,7 @@ class Economist(BasicNewsRecipe): def preprocess_html(self, soup): for img in soup.findAll('img', src=True): - img['src'] = img['src'].replace('economist.com/', + img['src'] = img['src'].replace('economist.com/', 'economist.com/cdn-cgi/image/width=600,quality=80,format=auto/') return soup diff --git a/recipes/lex_fridman_podcast.recipe b/recipes/lex_fridman_podcast.recipe index 6b8684cfd0..814c7d7902 100644 --- a/recipes/lex_fridman_podcast.recipe +++ b/recipes/lex_fridman_podcast.recipe @@ -1,5 +1,6 @@ from calibre.web.feeds.news import BasicNewsRecipe + class lexfridman(BasicNewsRecipe): title = 'Lex Fridman Podcast' description = (