Skip to content

Commit

Permalink
cleanup previous PR
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed May 10, 2024
1 parent e552405 commit 258a979
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
16 changes: 12 additions & 4 deletions recipes/economist.recipe
Expand Up @@ -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"):
Expand Down Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions recipes/economist_free.recipe
Expand Up @@ -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"):
Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions recipes/economist_world_ahead.recipe
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions recipes/lex_fridman_podcast.recipe
@@ -1,5 +1,6 @@
from calibre.web.feeds.news import BasicNewsRecipe


class lexfridman(BasicNewsRecipe):
title = 'Lex Fridman Podcast'
description = (
Expand Down

0 comments on commit 258a979

Please sign in to comment.