This commit is contained in:
Kovid Goyal 2024-07-23 13:01:42 +05:30
commit bcaebe54eb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 55 additions and 9 deletions

View File

@ -81,6 +81,19 @@ class TheAtlantic(BasicNewsRecipe):
language = 'en' language = 'en'
encoding = 'utf-8' encoding = 'utf-8'
recipe_specific_options = {
'date': {
'short': 'The date of the edition to download (YYYY/MM format)',
'long': 'For example, 2024/05'
}
}
def __init__(self, *args, **kwargs):
BasicNewsRecipe.__init__(self, *args, **kwargs)
d = self.recipe_specific_options.get('date')
if d and isinstance(d, str):
self.INDEX = 'https://www.theatlantic.com/magazine/toc/' + d + '/'
keep_only_tags = [ keep_only_tags = [
dict(itemprop=['headline']), dict(itemprop=['headline']),
classes( classes(

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
import json import json
from urllib.parse import quote, urlparse from urllib.parse import quote, urlparse
@ -118,6 +120,13 @@ class CaravanMagazine(BasicNewsRecipe):
return br return br
return br return br
recipe_specific_options = {
'date': {
'short': 'The date of the edition to download (MM-YYYY format)',
'long': 'For example, 07-2024'
}
}
def parse_index(self): def parse_index(self):
self.log( self.log(
'\n***\nif this recipe fails, report it on: ' '\n***\nif this recipe fails, report it on: '
@ -125,9 +134,11 @@ class CaravanMagazine(BasicNewsRecipe):
) )
api = 'https://api.caravanmagazine.in/api/trpc/magazines.getLatestIssue' api = 'https://api.caravanmagazine.in/api/trpc/magazines.getLatestIssue'
# for past editions d = self.recipe_specific_options.get('date')
# inp = json.dumps({"0":{"json":{"month":6,"year":2023}}}) if d and isinstance(d, str):
# api = 'https://api.caravanmagazine.in/api/trpc/magazines.getForMonthAndYear?batch=1&input=' + quote(inp, safe='') x = d.split('-')
inp = json.dumps({"0":{"json":{"month":int(x[0]),"year":int(x[1])}}})
api = 'https://api.caravanmagazine.in/api/trpc/magazines.getForMonthAndYear?batch=1&input=' + quote(inp, safe='')
raw = json.loads(self.index_to_soup(api, raw=True)) raw = json.loads(self.index_to_soup(api, raw=True))
if isinstance(raw, list): if isinstance(raw, list):

View File

@ -127,6 +127,13 @@ class ForeignAffairsRecipe(BasicNewsRecipe):
INDEX = 'https://www.foreignaffairs.com/magazine' INDEX = 'https://www.foreignaffairs.com/magazine'
recipe_specific_options = {
'issue': {
'short': 'Enter the Issue Number you want to download ',
'long': 'For example, 2024/103/1'
}
}
keep_only_tags = [ keep_only_tags = [
classes('article-header article-body article-lead-image article-body-text'), classes('article-header article-body article-lead-image article-body-text'),
] ]
@ -140,6 +147,10 @@ class ForeignAffairsRecipe(BasicNewsRecipe):
remove_empty_feeds = True remove_empty_feeds = True
def parse_index(self): def parse_index(self):
d = self.recipe_specific_options.get('issue')
if d and isinstance(d, str):
self.INDEX = 'https://www.foreignaffairs.com/issues/' + d
soup = self.index_to_soup(self.INDEX) soup = self.index_to_soup(self.INDEX)
# get dates # get dates
date = re.split(r'\s\|\s', self.tag_to_string( date = re.split(r'\s\|\s', self.tag_to_string(

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
from collections import defaultdict from collections import defaultdict
from calibre.web.feeds.news import BasicNewsRecipe, classes from calibre.web.feeds.news import BasicNewsRecipe, classes
@ -53,8 +55,20 @@ class Frontline(BasicNewsRecipe):
src.extract() src.extract()
return soup return soup
recipe_specific_options = {
'issue': {
'short': 'Enter the Issue Number you want to download\n(Volume-Issue format)',
'long': 'For example, 41-12'
}
}
def parse_index(self): def parse_index(self):
soup = self.index_to_soup('https://frontline.thehindu.com/current-issue/') issue_url = 'https://frontline.thehindu.com/current-issue/'
d = self.recipe_specific_options.get('issue')
if d and isinstance(d, str):
issue_url = 'https://frontline.thehindu.com/magazine/issue/vol' + d
soup = self.index_to_soup(issue_url)
if cover := soup.find('div', attrs={'class':'magazine'}): if cover := soup.find('div', attrs={'class':'magazine'}):
self.cover_url = cover.find(**classes('sptar-image')).img['data-original'].replace('_320', '_1200') self.cover_url = cover.find(**classes('sptar-image')).img['data-original'].replace('_320', '_1200')

View File

@ -72,7 +72,7 @@ class Harpers(BasicNewsRecipe):
edition = self.recipe_specific_options.get('date') edition = self.recipe_specific_options.get('date')
if edition and isinstance(edition, str): if edition and isinstance(edition, str):
url = 'https://harpers.org/archive/' + edition url = 'https://harpers.org/archive/' + edition
self.timefmt = ' [' +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'})

View File

@ -39,8 +39,6 @@ class TheHindufeeds(BasicNewsRecipe):
d = self.recipe_specific_options.get('days') d = self.recipe_specific_options.get('days')
if d and isinstance(d, str): if d and isinstance(d, str):
self.oldest_article = float(d) self.oldest_article = float(d)
if self.output_profile.short_name.startswith('kindle'):
self.title = 'The Hindu (Feeds) ' + date.today().strftime('%b %d, %Y')
ignore_duplicate_articles = {'url'} ignore_duplicate_articles = {'url'}

View File

@ -57,7 +57,6 @@ class ht(BasicNewsRecipe):
self.timefmt = ' [%s]' % today self.timefmt = ' [%s]' % today
day, month, year = (int(x) for x in today.split('/'))
today = today.replace('/', '%2F') today = today.replace('/', '%2F')
get_edition = index + '/Home/GetEditionSupplementHierarchy?EditionDate=' + today get_edition = index + '/Home/GetEditionSupplementHierarchy?EditionDate=' + today