recipe_specific_option updates

This commit is contained in:
unkn0w7n 2024-07-21 10:23:17 +05:30
parent eb601e992c
commit 68fc7ffb5c
4 changed files with 54 additions and 7 deletions

View File

@ -54,11 +54,24 @@ class Harpers(BasicNewsRecipe):
img['src'] = src.split()[0] img['src'] = src.split()[0]
return soup 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): def parse_index(self):
issues_soup = self.index_to_soup("https://harpers.org/issues/") issues_soup = self.index_to_soup("https://harpers.org/issues/")
a_ele = issues_soup.select_one("div.issue-card a") a_ele = issues_soup.select_one("div.issue-card a")
self.timefmt = ' [' + self.tag_to_string(a_ele.find(attrs={'class':'issue-title'})) + ']' self.timefmt = ' [' + self.tag_to_string(a_ele.find(attrs={'class':'issue-title'})) + ']'
url = a_ele['href'] 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) soup = self.index_to_soup(url)
cov_div = soup.find('div', attrs={'class':'issue-cover'}) cov_div = soup.find('div', attrs={'class':'issue-cover'})
if cov_div: if cov_div:

View File

@ -10,9 +10,6 @@ from calibre import prepare_string_for_xml as escape
from calibre.utils.iso8601 import parse_iso8601 from calibre.utils.iso8601 import parse_iso8601
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
edition = date.today().strftime('%B-%Y')
# edition = 'March-2023'
def classes(classes): def classes(classes):
q = frozenset(classes.split(' ')) q = frozenset(classes.split(' '))
@ -175,7 +172,18 @@ class NatGeo(BasicNewsRecipe):
.auth, .time, .sub { font-size:small; color:#5c5c5c; } .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): 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() url = 'https://www.nationalgeographic.com/magazine/issue/' + edition.lower()
self.log('Downloading ', url) self.log('Downloading ', url)
self.timefmt = ' [' + edition + ']' 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' 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()}) 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 = {} ans = {}
if photoart := soup.find(attrs={'class':lambda x: x and 'BgImagePromo__Container__Text__Link' in x.split()}): if photoart := soup.find(attrs={'class':lambda x: x and 'BgImagePromo__Container__Text__Link' in x.split()}):
section = 'Photo Essay' section = 'Photo Essay'

View File

@ -21,7 +21,7 @@ class Reuters(BasicNewsRecipe):
masthead_url = 'https://www.reutersprofessional.com/wp-content/uploads/2024/03/primary-logo.svg' masthead_url = 'https://www.reutersprofessional.com/wp-content/uploads/2024/03/primary-logo.svg'
language = 'en' language = 'en'
encoding = 'utf-8' encoding = 'utf-8'
oldest_article = 2 # days oldest_article = 1.2 # days
no_javascript = True no_javascript = True
no_stylesheets = True no_stylesheets = True
remove_attributes = ['style', 'height', 'width'] remove_attributes = ['style', 'height', 'width']
@ -30,10 +30,24 @@ class Reuters(BasicNewsRecipe):
extra_css = ''' extra_css = '''
.label, .auth { font-size:small; color:#202020; } .label, .auth { font-size:small; color:#202020; }
.figc { font-size:small; text-align:center; } .figc { font-size:small; }
img {display:block; margin:0 auto;} 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): def parse_index(self):
index = 'https://www.reuters.com' index = 'https://www.reuters.com'
today = datetime.now() today = datetime.now()

View File

@ -48,9 +48,21 @@ class tls(BasicNewsRecipe):
.det { font-size:small; color:#202020; font-weight:bold; } .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): def parse_index(self):
# for past edition, change the issue link below
issue = 'https://www.the-tls.co.uk/issues/current-issue/' 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) url = 'https://www.the-tls.co.uk/wp-json/tls/v2/contents-page/' + get_id(issue)
raw = self.index_to_soup(url, raw=True) raw = self.index_to_soup(url, raw=True)
data = json.loads(raw) data = json.loads(raw)