calibre/recipes/new_yorker.recipe
2014-10-24 09:46:31 +05:30

60 lines
2.0 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__license__ = 'GPL v3'
from calibre.web.feeds.news import BasicNewsRecipe
class NewYorker(BasicNewsRecipe):
title = u'New Yorker Magazine'
description = u'Content from the New Yorker website'
masthead_url = 'http://www.newyorker.com/images/elements/print/newyorker_printlogo.gif'
compress_news_images = True
compress_news_images_auto_size = 8
scale_news_images_to_device = False
scale_news_images = (768, 1024)
url_list = []
language = 'en'
__author__ = 'Krittika Goyal'
no_stylesheets = True
auto_cleanup = True
timefmt = ' [%b %d]'
encoding = 'utf-8'
extra_css = '''
.byline { font-size:xx-small; font-weight: bold;}
h3 { margin-bottom: 6px; }
.caption { font-size: xx-small; font-style: italic; font-weight: normal; }
'''
def parse_index(self):
soup = self.index_to_soup('http://www.newyorker.com/magazine?intcid=magazine')
ph = soup.find('div', attrs={'class':lambda x: x and 'cover-info' in x.split()})
if ph is not None:
img = ph.find('img', src=True)
if img is not None:
self.cover_url = img['src'].replace('-320.jpg', '.jpg')
articles = []
for story in soup.findAll('article', itemtype='http://schema.org/NewsArticle'):
h2 = story.find('h2')
url = h2.find('a', href=True)['href']
a = h2.find('a')
title = self.tag_to_string(a)
h3 = h2.findNextSibling('h3')
desc = ''
if h3 is not None:
desc += self.tag_to_string(h3)
p = h2.findNextSibling('p')
if p is not None:
desc += '. \n' + self.tag_to_string(p)
self.log('Found article:', title)
self.log('\t', url)
self.log('\t', desc)
articles.append({'title':title, 'url':url, 'date':'',
'description':desc})
return [('Current Issue', articles)]