mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update NatGeo
This commit is contained in:
parent
af0433edb3
commit
8e93f979f5
@ -106,7 +106,7 @@ def parse_article(edg):
|
|||||||
yield '<h1>' + escape(sc['sclTtl']) + '</h1>'
|
yield '<h1>' + escape(sc['sclTtl']) + '</h1>'
|
||||||
yield '<div class="byline">' + escape(sc['sclDsc']) + '</div>'
|
yield '<div class="byline">' + escape(sc['sclDsc']) + '</div>'
|
||||||
yield '<p>'
|
yield '<p>'
|
||||||
for line in parse_contributors(edg['cntrbGrp']):
|
for line in parse_contributors(edg.get('cntrbGrp', {})):
|
||||||
yield line
|
yield line
|
||||||
ts = parse_iso8601(edg['mdDt'], as_utc=False).strftime('%B %d, %Y')
|
ts = parse_iso8601(edg['mdDt'], as_utc=False).strftime('%B %d, %Y')
|
||||||
yield '<div class="time">Published: ' + escape(ts) + '</div>'
|
yield '<div class="time">Published: ' + escape(ts) + '</div>'
|
||||||
|
@ -105,7 +105,7 @@ def parse_article(edg):
|
|||||||
yield '<h1>' + escape(sc['sclTtl']) + '</h1>'
|
yield '<h1>' + escape(sc['sclTtl']) + '</h1>'
|
||||||
yield '<div class="byline">' + escape(sc['sclDsc']) + '</div>'
|
yield '<div class="byline">' + escape(sc['sclDsc']) + '</div>'
|
||||||
yield '<p>'
|
yield '<p>'
|
||||||
for line in parse_contributors(edg['cntrbGrp']):
|
for line in parse_contributors(edg.get('cntrbGrp', {})):
|
||||||
yield line
|
yield line
|
||||||
ts = parse_iso8601(edg['mdDt'], as_utc=False).strftime('%B %d, %Y')
|
ts = parse_iso8601(edg['mdDt'], as_utc=False).strftime('%B %d, %Y')
|
||||||
yield '<div class="time">Published: ' + escape(ts) + '</div>'
|
yield '<div class="time">Published: ' + escape(ts) + '</div>'
|
||||||
|
@ -110,7 +110,7 @@ def parse_article(edg):
|
|||||||
yield '<h1>' + escape(sc['sclTtl']) + '</h1>'
|
yield '<h1>' + escape(sc['sclTtl']) + '</h1>'
|
||||||
yield '<div class="byline">' + escape(sc['sclDsc']) + '</div>'
|
yield '<div class="byline">' + escape(sc['sclDsc']) + '</div>'
|
||||||
yield '<p>'
|
yield '<p>'
|
||||||
for line in parse_contributors(edg['cntrbGrp']):
|
for line in parse_contributors(edg.get('cntrbGrp', {})):
|
||||||
yield line
|
yield line
|
||||||
ts = parse_iso8601(edg['mdDt'], as_utc=False).strftime('%B %d, %Y')
|
ts = parse_iso8601(edg['mdDt'], as_utc=False).strftime('%B %d, %Y')
|
||||||
yield '<div class="time">Published: ' + escape(ts) + '</div>'
|
yield '<div class="time">Published: ' + escape(ts) + '</div>'
|
||||||
@ -187,14 +187,20 @@ class NatGeo(BasicNewsRecipe):
|
|||||||
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 = {}
|
||||||
ans2 = None
|
|
||||||
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()}):
|
||||||
ans2 = []
|
section = 'Photo Essay'
|
||||||
title = self.tag_to_string(photoart)
|
title = self.tag_to_string(photoart)
|
||||||
url = photoart['href']
|
url = photoart['href']
|
||||||
if url.startswith('/'):
|
if url.startswith('/'):
|
||||||
url = 'https://www.nationalgeographic.com' + url
|
url = 'https://www.nationalgeographic.com' + url
|
||||||
ans2.append(('Photo Essay', [{'title': title, 'url': url}]))
|
articles = ans.setdefault(section, [])
|
||||||
|
articles.append({'title': title, 'url': url})
|
||||||
|
for promo in soup.findAll(**classes('OneUpPromoCard__Content')):
|
||||||
|
url = promo.a['href']
|
||||||
|
section = self.tag_to_string(promo.find(**classes('SectionLabel')))
|
||||||
|
title = self.tag_to_string(promo.find(**classes('Card__Content__Heading')))
|
||||||
|
articles = ans.setdefault(section, [])
|
||||||
|
articles.append({'title': title, 'url': url})
|
||||||
for gird in soup.findAll(attrs={'class':'GridPromoTile'}):
|
for gird in soup.findAll(attrs={'class':'GridPromoTile'}):
|
||||||
for article in soup.findAll('article'):
|
for article in soup.findAll('article'):
|
||||||
a = article.find('a')
|
a = article.find('a')
|
||||||
@ -208,8 +214,6 @@ class NatGeo(BasicNewsRecipe):
|
|||||||
articles = ans.setdefault(section, [])
|
articles = ans.setdefault(section, [])
|
||||||
articles.append({'title': title, 'url': url})
|
articles.append({'title': title, 'url': url})
|
||||||
self.log(pformat(ans))
|
self.log(pformat(ans))
|
||||||
if ans2:
|
|
||||||
return list(ans.items()) + ans2
|
|
||||||
return list(ans.items())
|
return list(ans.items())
|
||||||
|
|
||||||
def preprocess_raw_html(self, raw_html, url):
|
def preprocess_raw_html(self, raw_html, url):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user