mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
recipe_specific_option updates
This commit is contained in:
parent
eb601e992c
commit
68fc7ffb5c
@ -54,11 +54,24 @@ class Harpers(BasicNewsRecipe):
|
||||
img['src'] = src.split()[0]
|
||||
return soup
|
||||
|
||||
recipe_specific_options = {
|
||||
'date': {
|
||||
'short': 'The date of the edition to download (YYYY/MM format)',
|
||||
'long': 'For example, 2023/08',
|
||||
}
|
||||
}
|
||||
|
||||
def parse_index(self):
|
||||
issues_soup = self.index_to_soup("https://harpers.org/issues/")
|
||||
a_ele = issues_soup.select_one("div.issue-card a")
|
||||
self.timefmt = ' [' + self.tag_to_string(a_ele.find(attrs={'class':'issue-title'})) + ']'
|
||||
url = a_ele['href']
|
||||
|
||||
edition = self.recipe_specific_options.get('date')
|
||||
if edition and isinstance(edition, str):
|
||||
url = 'https://harpers.org/archive/' + edition
|
||||
self.timefmt = ' [' +edition + ']'
|
||||
|
||||
soup = self.index_to_soup(url)
|
||||
cov_div = soup.find('div', attrs={'class':'issue-cover'})
|
||||
if cov_div:
|
||||
|
@ -10,9 +10,6 @@ from calibre import prepare_string_for_xml as escape
|
||||
from calibre.utils.iso8601 import parse_iso8601
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
|
||||
edition = date.today().strftime('%B-%Y')
|
||||
|
||||
# edition = 'March-2023'
|
||||
|
||||
def classes(classes):
|
||||
q = frozenset(classes.split(' '))
|
||||
@ -175,7 +172,18 @@ class NatGeo(BasicNewsRecipe):
|
||||
.auth, .time, .sub { font-size:small; color:#5c5c5c; }
|
||||
'''
|
||||
|
||||
recipe_specific_options = {
|
||||
'date': {
|
||||
'short': 'The date of the edition to download (Month-YYYY format)',
|
||||
'long': 'For example, March-2023'
|
||||
}
|
||||
}
|
||||
|
||||
def parse_index(self):
|
||||
edition = date.today().strftime('%B-%Y')
|
||||
d = self.recipe_specific_options.get('date')
|
||||
if d and isinstance(d, str):
|
||||
edition = d
|
||||
url = 'https://www.nationalgeographic.com/magazine/issue/' + edition.lower()
|
||||
self.log('Downloading ', url)
|
||||
self.timefmt = ' [' + edition + ']'
|
||||
@ -185,7 +193,7 @@ class NatGeo(BasicNewsRecipe):
|
||||
self.cover_url = soup.find('meta', attrs={'property':'og:image'})['content'].split('?')[0] + '?w=1000'
|
||||
|
||||
name = soup.find(attrs={'class':lambda x: x and 'Header__Description' in x.split()})
|
||||
self.title = 'National Geographic ' + self.tag_to_string(name)
|
||||
# self.title = 'National Geographic ' + self.tag_to_string(name)
|
||||
ans = {}
|
||||
if photoart := soup.find(attrs={'class':lambda x: x and 'BgImagePromo__Container__Text__Link' in x.split()}):
|
||||
section = 'Photo Essay'
|
||||
|
@ -21,7 +21,7 @@ class Reuters(BasicNewsRecipe):
|
||||
masthead_url = 'https://www.reutersprofessional.com/wp-content/uploads/2024/03/primary-logo.svg'
|
||||
language = 'en'
|
||||
encoding = 'utf-8'
|
||||
oldest_article = 2 # days
|
||||
oldest_article = 1.2 # days
|
||||
no_javascript = True
|
||||
no_stylesheets = True
|
||||
remove_attributes = ['style', 'height', 'width']
|
||||
@ -30,10 +30,24 @@ class Reuters(BasicNewsRecipe):
|
||||
|
||||
extra_css = '''
|
||||
.label, .auth { font-size:small; color:#202020; }
|
||||
.figc { font-size:small; text-align:center; }
|
||||
.figc { font-size:small; }
|
||||
img {display:block; margin:0 auto;}
|
||||
'''
|
||||
|
||||
recipe_specific_options = {
|
||||
'days': {
|
||||
'short': 'Oldest article to download from this news source. In days ',
|
||||
'long': 'For example, 0.5, gives you articles from the past 12 hours',
|
||||
'default': str(oldest_article)
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
BasicNewsRecipe.__init__(self, *args, **kwargs)
|
||||
d = self.recipe_specific_options.get('days')
|
||||
if d and isinstance(d, str):
|
||||
self.oldest_article = float(d)
|
||||
|
||||
def parse_index(self):
|
||||
index = 'https://www.reuters.com'
|
||||
today = datetime.now()
|
||||
|
@ -48,9 +48,21 @@ class tls(BasicNewsRecipe):
|
||||
.det { font-size:small; color:#202020; font-weight:bold; }
|
||||
'''
|
||||
|
||||
recipe_specific_options = {
|
||||
'date': {
|
||||
'short': 'The date of the edition to download\nlower case Month-DD-YYYY format',
|
||||
'long': 'For example, july-12-2024',
|
||||
'default': 'current-issue'
|
||||
}
|
||||
}
|
||||
|
||||
def parse_index(self):
|
||||
# for past edition, change the issue link below
|
||||
issue = 'https://www.the-tls.co.uk/issues/current-issue/'
|
||||
|
||||
d = self.recipe_specific_options.get('date')
|
||||
if d and isinstance(d, str):
|
||||
issue = 'https://www.the-tls.co.uk/issues/' + d + '/'
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user