mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update National Geographic Magazine
This commit is contained in:
parent
7275d89cb5
commit
bfe6099a3d
@ -1,46 +1,49 @@
|
|||||||
from calibre.web.feeds.recipes import BasicNewsRecipe
|
from calibre.web.feeds.recipes import BasicNewsRecipe
|
||||||
|
|
||||||
class NatGeoMag(BasicNewsRecipe):
|
class NGM(BasicNewsRecipe):
|
||||||
title = 'National Geographic Mag'
|
|
||||||
__author__ = 'Terminal Veracity'
|
|
||||||
description = 'The National Geographic Magazine'
|
|
||||||
publisher = 'National Geographic'
|
|
||||||
oldest_article = 31
|
|
||||||
max_articles_per_feed = 50
|
|
||||||
category = 'geography, magazine'
|
|
||||||
language = 'en'
|
|
||||||
publication_type = 'magazine'
|
|
||||||
cover_url = 'http://www.yourlogoresources.com/wp-content/uploads/2011/09/national-geographic-logo.jpg'
|
|
||||||
use_embedded_content = False
|
|
||||||
no_stylesheets = True
|
|
||||||
remove_javascript = True
|
|
||||||
recursions = 1
|
|
||||||
remove_empty_feeds = True
|
|
||||||
feeds = [('National Geographic Magazine', 'http://feeds.nationalgeographic.com/ng/NGM/NGM_Magazine')]
|
|
||||||
remove_tags = [dict(name='div', attrs={'class':['nextpage_continue', 'subscribe']})]
|
|
||||||
keep_only_tags = [dict(attrs={'class':'main_3narrow'})]
|
|
||||||
extra_css = """
|
|
||||||
h1 {font-size: large; font-weight: bold; margin: .5em 0; }
|
|
||||||
h2 {font-size: large; font-weight: bold; margin: .5em 0; }
|
|
||||||
h3 {font-size: medium; font-weight: bold; margin: 0 0; }
|
|
||||||
.article_credits_author {font-size: small; font-style: italic; }
|
|
||||||
.article_credits_photographer {font-size: small; font-style: italic; display: inline }
|
|
||||||
"""
|
|
||||||
|
|
||||||
def parse_feeds(self):
|
title = 'National Geographic Magazine'
|
||||||
feeds = BasicNewsRecipe.parse_feeds(self)
|
__author__ = 'Krittika Goyal'
|
||||||
for feed in feeds:
|
description = 'National Geographic Magazine'
|
||||||
for article in feed.articles[:]:
|
timefmt = ' [%d %b, %Y]'
|
||||||
if 'Flashback' in article.title:
|
|
||||||
feed.articles.remove(article)
|
no_stylesheets = True
|
||||||
elif 'Desktop Wallpaper' in article.title:
|
auto_cleanup = True
|
||||||
feed.articles.remove(article)
|
auto_cleanup_keep = '//div[@class="featurepic"]'
|
||||||
elif 'Visions of Earth' in article.title:
|
|
||||||
feed.articles.remove(article)
|
def nejm_get_index(self):
|
||||||
elif 'Your Shot' in article.title:
|
return self.index_to_soup('http://ngm.nationalgeographic.com/2013/10/table-of-contents')
|
||||||
feed.articles.remove(article)
|
|
||||||
elif 'MyShot' in article.title:
|
# To parse artice toc
|
||||||
feed.articles.remove(article)
|
def parse_index(self):
|
||||||
elif 'Field Test' in article.title:
|
soup = self.nejm_get_index()
|
||||||
feed.articles.remove(article)
|
tocfull = soup.find('div', attrs={'class':'coltoc'})
|
||||||
return feeds
|
|
||||||
|
toc = tocfull.find('div', attrs={'class':'more_section'})
|
||||||
|
|
||||||
|
articles = []
|
||||||
|
feeds = []
|
||||||
|
section_title = 'Features'
|
||||||
|
for x in toc.findAll(True):
|
||||||
|
if x.name == 'a':
|
||||||
|
# Article found
|
||||||
|
title = self.tag_to_string(x)
|
||||||
|
url = x.get('href', False)
|
||||||
|
if not url or not title:
|
||||||
|
continue
|
||||||
|
url = 'http://ngm.nationalgeographic.com' + url
|
||||||
|
self.log('\t\tFound article:', title)
|
||||||
|
self.log('\t\t\t', url)
|
||||||
|
articles.append({'title': title, 'url':url,
|
||||||
|
'description':'', 'date':''})
|
||||||
|
feeds.append((section_title, articles))
|
||||||
|
|
||||||
|
art1 = tocfull.findAll('a')[1]
|
||||||
|
art1_title = self.tag_to_string(art1.find('div', attrs={'class': 'toched'}))
|
||||||
|
art1_url = art1.get('href', False)
|
||||||
|
art1_url = 'http://ngm.nationalgeographic.com' + art1_url
|
||||||
|
art1feed = {'title': art1_title, 'url':art1_url,
|
||||||
|
'description':'', 'date':''}
|
||||||
|
feeds.append(('Cover Story', [art1feed]))
|
||||||
|
|
||||||
|
return feeds
|
||||||
|
Loading…
x
Reference in New Issue
Block a user