Debian Codegraph @

recipes/the_nation.recipe

raw
1 __license__ = 'GPL v3'
2 __copyright__ = '2008 - 2011, Darko Miletic <darko.miletic at gmail.com>'
3 '''
4 thenation.com
5 '''
6 from calibre.web.feeds.news import BasicNewsRecipe
7
8
9 def classes(classes):
10 q = frozenset(classes.split(' '))
11 return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
12
13
14 class Thenation(BasicNewsRecipe):
15 title = 'The Nation'
16 __author__ = 'Darko Miletic'
17 description = 'Unconventional Wisdom Since 1865'
18 publisher = 'The Nation'
19 category = 'news, politics, USA'
20 oldest_article = 120
21 encoding = 'utf-8'
22 max_articles_per_feed = 100
23 no_stylesheets = True
24 language = 'en'
25 use_embedded_content = False
26 delay = 1
27 login_url = 'https://www.thenation.com/login/'
28 publication_type = 'magazine'
29 needs_subscription = 'optional'
30 exra_css = '''
31 body{font-family: Arial,Helvetica,sans-serif;}
32 .print-created{font-size: small;}
33 .caption{display: block; font-size: x-small;}
34 '''
35
36 conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language}
37
38 keep_only_tags = [
39 classes('title subtitle byline article-body-inner'),
40 ]
41 remove_tags = [
42 dict(name=['link', 'iframe', 'base', 'meta', 'object', 'embed', 'script']),
43 classes('email-signup-module current-issue related-newarticle related-multi series-modules'),
44 ]
45 remove_attributes = ['lang']
46
47 feeds = [('Articles', 'http://www.thenation.com/rss/articles')]
48
49 def get_browser(self):
50 br = BasicNewsRecipe.get_browser(self)
51 br.open('http://www.thenation.com/')
52 if self.username is not None and self.password is not None:
53 br.open(self.login_url)
54 br.select_form(predicate=lambda form: form.attrs.get('id') == 'lightboxform')
55 br['e_mail'] = self.username
56 br['pwd'] = self.password
57 # The form uses reCaptcha and JS so no go
58 # br.submit()
59 return br
60
61 def get_cover_url(self):
62 soup = self.index_to_soup('http://www.thenation.com/issue/')
63 item = soup.find('div', attrs={'id': 'cover-wrapper'})
64 if item:
65 return item.img['src']
66 return None