diff --git a/recipes/caravan_magazine.recipe b/recipes/caravan_magazine.recipe index f0ec508791..3de9e663f7 100644 --- a/recipes/caravan_magazine.recipe +++ b/recipes/caravan_magazine.recipe @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 import json from urllib.parse import quote, urlparse @@ -118,6 +120,13 @@ class CaravanMagazine(BasicNewsRecipe): 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): self.log( '\n***\nif this recipe fails, report it on: ' @@ -125,9 +134,11 @@ class CaravanMagazine(BasicNewsRecipe): ) api = 'https://api.caravanmagazine.in/api/trpc/magazines.getLatestIssue' - # for past editions - # inp = json.dumps({"0":{"json":{"month":6,"year":2023}}}) - # api = 'https://api.caravanmagazine.in/api/trpc/magazines.getForMonthAndYear?batch=1&input=' + quote(inp, safe='') + d = self.recipe_specific_options.get('date') + if d and isinstance(d, str): + 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)) if isinstance(raw, list): diff --git a/recipes/foreignaffairs.recipe b/recipes/foreignaffairs.recipe index dd0888c5b2..405d598fc7 100644 --- a/recipes/foreignaffairs.recipe +++ b/recipes/foreignaffairs.recipe @@ -127,6 +127,13 @@ class ForeignAffairsRecipe(BasicNewsRecipe): 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 = [ classes('article-header article-body article-lead-image article-body-text'), ] @@ -140,6 +147,10 @@ class ForeignAffairsRecipe(BasicNewsRecipe): remove_empty_feeds = True 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) # get dates date = re.split(r'\s\|\s', self.tag_to_string( diff --git a/recipes/frontline.recipe b/recipes/frontline.recipe index fb23018f18..0655f5745a 100644 --- a/recipes/frontline.recipe +++ b/recipes/frontline.recipe @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 from collections import defaultdict from calibre.web.feeds.news import BasicNewsRecipe, classes @@ -53,8 +55,20 @@ class Frontline(BasicNewsRecipe): src.extract() 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): - 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'}): self.cover_url = cover.find(**classes('sptar-image')).img['data-original'].replace('_320', '_1200') @@ -82,4 +96,4 @@ class Frontline(BasicNewsRecipe): continue self.log(section, '\n\t', title, '\n\t', desc, '\n\t\t', url) feeds_dict[section].append({"title": title, "url": url, "description": desc}) - return [(section, articles) for section, articles in feeds_dict.items()] \ No newline at end of file + return [(section, articles) for section, articles in feeds_dict.items()]