mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update New Yorker
This commit is contained in:
parent
01c21f4288
commit
624482eddd
@ -77,10 +77,14 @@ class barrons(BasicNewsRecipe):
|
|||||||
return br
|
return br
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
|
self.log(
|
||||||
|
'\n***\nif this recipe fails, report it on: '
|
||||||
|
'https://www.mobileread.com/forums/forumdisplay.php?f=228\n***\n'
|
||||||
|
)
|
||||||
archive = self.index_to_soup('https://www.barrons.com/magazine?archives=' + date.today().strftime('%Y'))
|
archive = self.index_to_soup('https://www.barrons.com/magazine?archives=' + date.today().strftime('%Y'))
|
||||||
issue = archive.find(**prefixed_classes('BarronsTheme--archive-box--'))
|
issue = archive.find(**prefixed_classes('BarronsTheme--archive-box--'))
|
||||||
self.timefmt = ' [' + self.tag_to_string(issue.find(**prefixed_classes('BarronsTheme--date--'))) + ']'
|
self.timefmt = ' [' + self.tag_to_string(issue.find(**prefixed_classes('BarronsTheme--date--'))) + ']'
|
||||||
self.log(self.timefmt)
|
self.description = self.tag_to_string(issue.find(**prefixed_classes('BarronsTheme--headline--')))
|
||||||
self.cover_url = issue.img['src'].split('?')[0]
|
self.cover_url = issue.img['src'].split('?')[0]
|
||||||
|
|
||||||
ans = defaultdict(list)
|
ans = defaultdict(list)
|
||||||
|
@ -92,8 +92,8 @@ class CaravanMagazine(BasicNewsRecipe):
|
|||||||
'https://www.mobileread.com/forums/forumdisplay.php?f=228\n***\n'
|
'https://www.mobileread.com/forums/forumdisplay.php?f=228\n***\n'
|
||||||
)
|
)
|
||||||
api = 'https://api.caravanmagazine.in/api/trpc/magazines.getLatestIssue'
|
api = 'https://api.caravanmagazine.in/api/trpc/magazines.getLatestIssue'
|
||||||
# https://api.caravanmagazine.in/api/trpc/magazines.getForMonthAndYear?batch=1&input=
|
# api = 'https://api.caravanmagazine.in/api/trpc/magazines.getForMonthAndYear?batch=1&' + \
|
||||||
# %7B%220%22%3A%7B%22json%22%3A%7B%22month%22%3A 2 %2C%22year%22%3A 2024 %7D%7D%7D
|
# 'input=%7B%220%22%3A%7B%22json%22%3A%7B%22month%22%3A' + '2' + '%2C%22year%22%3A' + '2024' + '%7D%7D%7D'
|
||||||
# input={"0":{"json":{"month":2,"year":2024}}}
|
# input={"0":{"json":{"month":2,"year":2024}}}
|
||||||
raw = self.index_to_soup(api, raw=True)
|
raw = self.index_to_soup(api, raw=True)
|
||||||
data = json.loads(raw)['result']['data']['json']
|
data = json.loads(raw)['result']['data']['json']
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import defaultdict
|
||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.ebooks.BeautifulSoup import Tag
|
from calibre.ebooks.BeautifulSoup import Tag
|
||||||
@ -15,14 +15,6 @@ def absurl(x):
|
|||||||
x = 'https://www.newyorker.com' + x
|
x = 'https://www.newyorker.com' + x
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
def new_tag(soup, name, attrs=()):
|
|
||||||
impl = getattr(soup, 'new_tag', None)
|
|
||||||
if impl is not None:
|
|
||||||
return impl(name, attrs=dict(attrs))
|
|
||||||
return Tag(soup, name, attrs=attrs or None)
|
|
||||||
|
|
||||||
|
|
||||||
class NewYorker(BasicNewsRecipe):
|
class NewYorker(BasicNewsRecipe):
|
||||||
|
|
||||||
title = "The New Yorker Magazine"
|
title = "The New Yorker Magazine"
|
||||||
@ -36,22 +28,16 @@ class NewYorker(BasicNewsRecipe):
|
|||||||
encoding = 'utf-8'
|
encoding = 'utf-8'
|
||||||
extra_css = '''
|
extra_css = '''
|
||||||
img { display:block; margin:0 auto; }
|
img { display:block; margin:0 auto; }
|
||||||
.byline { font-size:smaller; font-weight: bold;}
|
.rubric__name, .byline, time, .caption { font-size:small; }
|
||||||
|
.byline, .rubric__name { font-size:smaller; font-weight: bold;}
|
||||||
h3 { margin-bottom: 6px; }
|
h3 { margin-bottom: 6px; }
|
||||||
.caption { font-size: smaller; font-style: italic; font-weight: normal; }
|
.caption, .contributors { font-size: smaller; font-style: italic; font-weight: normal; }
|
||||||
|
.content-header__accreditation { font-style:italic; }
|
||||||
'''
|
'''
|
||||||
|
|
||||||
keep_only_tags = [
|
keep_only_tags = [
|
||||||
prefixed_classes(
|
|
||||||
'SplitScreenContentHeaderHed- SplitScreenContentHeaderDek- SplitScreenContentHeaderByline-'
|
|
||||||
' SplitScreenContentHeaderLeadWrapper-'
|
|
||||||
),
|
|
||||||
classes(
|
classes(
|
||||||
'split-screen-content-header__dek split-screen-content-header__hed'
|
'article__content-header article__body contributors'
|
||||||
' content-header__dek content-header__hed content-header__publish-date content-header__lede-block'
|
|
||||||
' content-header__rubric--issue-date content-header__lead-asset'
|
|
||||||
' split-screen-content-header__publish-date split-screen-content-header__lede-block'
|
|
||||||
' article__body bylines featured-image byline-and-date inset-mobile-crop-image hero-image-caption'
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
@ -127,57 +113,31 @@ class NewYorker(BasicNewsRecipe):
|
|||||||
|
|
||||||
soup = self.index_to_soup(
|
soup = self.index_to_soup(
|
||||||
'https://www.newyorker.com/magazine?intcid=magazine')
|
'https://www.newyorker.com/magazine?intcid=magazine')
|
||||||
stories = OrderedDict() # So we can list sections in order
|
feeds_dict = defaultdict(list)
|
||||||
|
for section in soup.findAll('section',
|
||||||
# Iterate sections of content
|
attrs={'class': lambda x: x and 'SummaryRiverSection-' in x}):
|
||||||
|
for h2 in section.findAll(attrs={'class':lambda x: x and 'SectionTitleHed-' in x}):
|
||||||
for section_soup in soup.findAll(
|
secname = self.tag_to_string(h2)
|
||||||
attrs={'class': lambda x: x and 'MagazinePageSection__section___21cc7' in x}):
|
self.log(secname)
|
||||||
section = section_soup.find('h2').text
|
articles = []
|
||||||
self.log("Found section:", section)
|
for a in section.findAll('a', href=True, attrs={'class':lambda x: x and 'summary-item__hed-link' in x}):
|
||||||
|
section = secname
|
||||||
# Iterate stories in section
|
|
||||||
|
|
||||||
is_mail_section = (section == "Mail")
|
|
||||||
|
|
||||||
if is_mail_section:
|
|
||||||
cname = "Link__link___"
|
|
||||||
else:
|
|
||||||
cname = "River__riverItemContent___"
|
|
||||||
|
|
||||||
for story in section_soup.findAll(
|
|
||||||
attrs={'class': lambda x: x and cname in x}):
|
|
||||||
|
|
||||||
title = ""
|
|
||||||
url = ""
|
|
||||||
desc = ""
|
|
||||||
|
|
||||||
if is_mail_section:
|
|
||||||
title = story.text
|
|
||||||
url = absurl(story['href'])
|
|
||||||
else:
|
|
||||||
h4 = story.find('h4')
|
|
||||||
title = self.tag_to_string(h4)
|
|
||||||
a = story.find('h4').parent
|
|
||||||
url = absurl(a['href'])
|
url = absurl(a['href'])
|
||||||
# Get description
|
title = self.tag_to_string(a)
|
||||||
body = story.find(attrs={'class': 'River__dek___CayIg'})
|
desc = ''
|
||||||
if body is not None:
|
summ = a.find_next_sibling(attrs={'class':lambda x: x and 'summary-item__dek' in x})
|
||||||
desc = str(body.contents[0])
|
if summ:
|
||||||
|
desc = self.tag_to_string(summ)
|
||||||
|
byl = a.find_next_sibling(attrs={'class':lambda x: x and 'summary-item__byline-' in x})
|
||||||
|
if byl:
|
||||||
|
desc = self.tag_to_string(byl) + ' | ' + desc
|
||||||
|
rub = a.find_previous_sibling(attrs={'class':lambda x: x and 'summary-item__rubric' in x})
|
||||||
|
if rub:
|
||||||
|
desc = self.tag_to_string(rub) + ' | ' + desc
|
||||||
|
self.log('\t', title, '\n\t', desc, '\n\t\t', url)
|
||||||
|
feeds_dict[section].append({"title": title, "url": url, "description": desc})
|
||||||
|
return feeds_dict.items()
|
||||||
|
|
||||||
self.log('Found article:', title)
|
|
||||||
self.log('\t' + url)
|
|
||||||
self.log('\t' + desc)
|
|
||||||
self.log('')
|
|
||||||
|
|
||||||
if section not in stories:
|
|
||||||
stories[section] = []
|
|
||||||
stories[section].append({
|
|
||||||
'title': title,
|
|
||||||
'url': url,
|
|
||||||
'description': desc})
|
|
||||||
|
|
||||||
return [(k, stories[k]) for k, v in stories.items()]
|
|
||||||
|
|
||||||
# The New Yorker changes the content it delivers based on cookies, so the
|
# The New Yorker changes the content it delivers based on cookies, so the
|
||||||
# following ensures that we send no cookies
|
# following ensures that we send no cookies
|
||||||
|
Loading…
x
Reference in New Issue
Block a user