Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tls_mag.recipe #2460

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions recipes/tls_mag.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_id(url):
return re.search('\?p=(\S+)>', str(rq.info())).group(1)


class tls(BasicNewsRecipe):
class TLS(BasicNewsRecipe):
title = 'Times Literary Supplement'
__author__ = 'unkn0wn'
description = (
Expand All @@ -39,7 +39,7 @@ class tls(BasicNewsRecipe):
.desc { font-style:italic; color:#202020; }
.auth { font-size:small; }
em, blockquote { color:#202020; }
.det { font-size:small; color:#202020; font-weight:bold; }
.det { font-size:small; color:#202020; }
'''

recipe_specific_options = {
Expand All @@ -60,7 +60,7 @@ class tls(BasicNewsRecipe):
url = 'https://www.the-tls.co.uk/wp-json/tls/v2/contents-page/' + get_id(issue)
raw = self.index_to_soup(url, raw=True)
data = json.loads(raw)
self.cover_url = data['featuredimage']['full_image'] + '?w600'
self.cover_url = data['featuredimage']['full_image'].split('?')[0] + '?w=600'
self.timefmt = ' [' + data['issuedateline']['issuedate'] + ']'
if data['issuedateline']['issuenumber']:
self.description = 'Issue ' + data['issuedateline']['issuenumber']
Expand Down Expand Up @@ -93,6 +93,11 @@ class tls(BasicNewsRecipe):
self.log(' ', title, '\n\t', desc, '\n\t', url)
return ({ 'title': title, 'description': desc, 'url': url })

def preprocess_html(self, soup):
for img in soup.findAll('img', attrs={'src':True}):
img['src'] = img['src'].split('?')[0] + '?w=600'
return soup

def preprocess_raw_html(self, raw, *a):
pg = re.search(r'var tlsPageObject = ({.+)', raw).group(1)
data = json.JSONDecoder().raw_decode(pg)[0]
Expand Down
Loading