mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
caravan, foreign affairs, frontline
This commit is contained in:
parent
9e0bf731d3
commit
402b952f4d
@ -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):
|
||||||
|
@ -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(
|
||||||
|
@ -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')
|
||||||
@ -82,4 +96,4 @@ class Frontline(BasicNewsRecipe):
|
|||||||
continue
|
continue
|
||||||
self.log(section, '\n\t', title, '\n\t', desc, '\n\t\t', url)
|
self.log(section, '\n\t', title, '\n\t', desc, '\n\t\t', url)
|
||||||
feeds_dict[section].append({"title": title, "url": url, "description": desc})
|
feeds_dict[section].append({"title": title, "url": url, "description": desc})
|
||||||
return [(section, articles) for section, articles in feeds_dict.items()]
|
return [(section, articles) for section, articles in feeds_dict.items()]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user