mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make recipe_specific_options usage compatible with old versions of calibre
This commit is contained in:
parent
601d13e98d
commit
eb601e992c
@ -87,7 +87,7 @@ class Bloomberg(BasicNewsRecipe):
|
||||
sec = self.index_to_soup(inx + '/wssmobile/v1/bw/news/list?limit=1', raw=True)
|
||||
id = json.loads(sec)['magazines'][0]['id']
|
||||
past_edition = self.recipe_specific_options.get('date')
|
||||
if past_edition:
|
||||
if past_edition and isinstance(past_edition, str):
|
||||
id = past_edition
|
||||
edit = self.index_to_soup(inx + '/wssmobile/v1/bw/news/week/' + id, raw=True)
|
||||
d = json.loads(edit)
|
||||
|
@ -81,14 +81,15 @@ class Bloomberg(BasicNewsRecipe):
|
||||
recipe_specific_options = {
|
||||
'days': {
|
||||
'short': 'Oldest article to download from this news source. In days ',
|
||||
'long': 'For example, 0.5, gives you articles for the past 12 hours'
|
||||
'long': 'For example, 0.5, gives you articles for the past 12 hours',
|
||||
'default': str(oldest_article),
|
||||
}
|
||||
}
|
||||
|
||||
def parse_index(self):
|
||||
d = self.recipe_specific_options.get('days')
|
||||
if d:
|
||||
self.oldest_article = d
|
||||
if d and isinstance(d, str):
|
||||
self.oldest_article = float(d)
|
||||
inx = 'https://cdn-mobapi.bloomberg.com'
|
||||
sec = self.index_to_soup(inx + '/wssmobile/v1/navigation/bloomberg_app/search-v2', raw=True)
|
||||
sec_data = json.loads(sec)['searchNav']
|
||||
|
@ -215,7 +215,7 @@ class Economist(BasicNewsRecipe):
|
||||
|
||||
def publication_date(self):
|
||||
edition_date = self.recipe_specific_options.get('date')
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
return parse_only_date(edition_date, as_utc=False)
|
||||
url = self.browser.open("https://www.economist.com/printedition").geturl()
|
||||
return parse_only_date(url.split("/")[-1], as_utc=False)
|
||||
@ -245,7 +245,7 @@ class Economist(BasicNewsRecipe):
|
||||
'operationName': 'LatestWeeklyAutoEditionQuery',
|
||||
'variables': '{"ref":"/content/d06tg8j85rifiq3oo544c6b9j61dno2n"}',
|
||||
}
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
url = 'https://www.economist.com/weeklyedition/' + edition_date
|
||||
soup = self.index_to_soup(url)
|
||||
script_tag = soup.find("script", id="__NEXT_DATA__")
|
||||
@ -268,7 +268,7 @@ class Economist(BasicNewsRecipe):
|
||||
|
||||
def economist_parse_index(self, raw):
|
||||
edition_date = self.recipe_specific_options.get('date')
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
data = json.loads(raw)['data']['section']
|
||||
else:
|
||||
data = json.loads(raw)['data']['canonical']['hasPart']['parts'][0]
|
||||
@ -336,7 +336,7 @@ class Economist(BasicNewsRecipe):
|
||||
def parse_index(self):
|
||||
edition_date = self.recipe_specific_options.get('date')
|
||||
# return self.economist_test_article()
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
url = 'https://www.economist.com/weeklyedition/' + edition_date
|
||||
self.timefmt = ' [' + edition_date + ']'
|
||||
else:
|
||||
@ -423,10 +423,11 @@ class Economist(BasicNewsRecipe):
|
||||
x.set('style', 'color:#404040;')
|
||||
raw = etree.tostring(root, encoding='unicode')
|
||||
return raw
|
||||
|
||||
def parse_index_from_printedition(self):
|
||||
# return self.economist_test_article()
|
||||
edition_date = self.recipe_specific_options.get('date')
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
url = 'https://www.economist.com/weeklyedition/' + edition_date
|
||||
self.timefmt = ' [' + edition_date + ']'
|
||||
else:
|
||||
|
@ -215,7 +215,7 @@ class Economist(BasicNewsRecipe):
|
||||
|
||||
def publication_date(self):
|
||||
edition_date = self.recipe_specific_options.get('date')
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
return parse_only_date(edition_date, as_utc=False)
|
||||
url = self.browser.open("https://www.economist.com/printedition").geturl()
|
||||
return parse_only_date(url.split("/")[-1], as_utc=False)
|
||||
@ -245,7 +245,7 @@ class Economist(BasicNewsRecipe):
|
||||
'operationName': 'LatestWeeklyAutoEditionQuery',
|
||||
'variables': '{"ref":"/content/d06tg8j85rifiq3oo544c6b9j61dno2n"}',
|
||||
}
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
url = 'https://www.economist.com/weeklyedition/' + edition_date
|
||||
soup = self.index_to_soup(url)
|
||||
script_tag = soup.find("script", id="__NEXT_DATA__")
|
||||
@ -268,7 +268,7 @@ class Economist(BasicNewsRecipe):
|
||||
|
||||
def economist_parse_index(self, raw):
|
||||
edition_date = self.recipe_specific_options.get('date')
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
data = json.loads(raw)['data']['section']
|
||||
else:
|
||||
data = json.loads(raw)['data']['canonical']['hasPart']['parts'][0]
|
||||
@ -336,7 +336,7 @@ class Economist(BasicNewsRecipe):
|
||||
def parse_index(self):
|
||||
edition_date = self.recipe_specific_options.get('date')
|
||||
# return self.economist_test_article()
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
url = 'https://www.economist.com/weeklyedition/' + edition_date
|
||||
self.timefmt = ' [' + edition_date + ']'
|
||||
else:
|
||||
@ -423,10 +423,11 @@ class Economist(BasicNewsRecipe):
|
||||
x.set('style', 'color:#404040;')
|
||||
raw = etree.tostring(root, encoding='unicode')
|
||||
return raw
|
||||
|
||||
def parse_index_from_printedition(self):
|
||||
# return self.economist_test_article()
|
||||
edition_date = self.recipe_specific_options.get('date')
|
||||
if edition_date:
|
||||
if edition_date and isinstance(edition_date, str):
|
||||
url = 'https://www.economist.com/weeklyedition/' + edition_date
|
||||
self.timefmt = ' [' + edition_date + ']'
|
||||
else:
|
||||
|
@ -62,7 +62,7 @@ class TheHindu(BasicNewsRecipe):
|
||||
def parse_index(self):
|
||||
|
||||
local_edition = self.recipe_specific_options.get('location')
|
||||
if local_edition:
|
||||
if local_edition and isinstance(local_edition, str):
|
||||
local_edition = 'th_' + local_edition
|
||||
else:
|
||||
local_edition = 'th_international'
|
||||
@ -70,7 +70,7 @@ class TheHindu(BasicNewsRecipe):
|
||||
past_edition = self.recipe_specific_options.get('date')
|
||||
|
||||
dt = date.today()
|
||||
if past_edition:
|
||||
if past_edition and isinstance(past_edition, str):
|
||||
year, month, day = (int(x) for x in past_edition.split('-'))
|
||||
dt = date(year, month, day)
|
||||
|
||||
|
@ -53,7 +53,7 @@ class PsychologyToday(BasicNewsRecipe):
|
||||
a = soup.find(**classes('magazine-thumbnail')).a
|
||||
url = a['href']
|
||||
past_edition = self.recipe_specific_options.get('date')
|
||||
if past_edition:
|
||||
if past_edition and isinstance(past_edition, str):
|
||||
url = '/us/magazine/archive/' + past_edition
|
||||
soup = self.index_to_soup(absurl(url))
|
||||
cov = soup.find(**classes('content-header--cover-image'))
|
||||
|
@ -107,7 +107,8 @@ class WSJ(BasicNewsRecipe):
|
||||
return soup
|
||||
|
||||
def _download_cover(self):
|
||||
if not self.recipe_specific_options.get('date'):
|
||||
d = self.recipe_specific_options.get('date')
|
||||
if not (d and isinstance(d, str)):
|
||||
import os
|
||||
from contextlib import closing
|
||||
|
||||
@ -143,7 +144,7 @@ class WSJ(BasicNewsRecipe):
|
||||
past_edition = self.recipe_specific_options.get('date')
|
||||
|
||||
for itm in catalog['items']:
|
||||
if past_edition:
|
||||
if past_edition and isinstance(past_edition, str):
|
||||
if itm['key'] == 'ITPNEXTGEN' + past_edition:
|
||||
key = itm['key']
|
||||
manifest = itm['manifest']
|
||||
|
Loading…
x
Reference in New Issue
Block a user