Debian Codegraph @

recipes/phillosophy_now.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3 from collections import OrderedDict
4
5 from calibre import browser
6 from calibre.web.feeds.news import BasicNewsRecipe, classes
7
8
9 class PhilosophyNow(BasicNewsRecipe):
10 title = 'Philosophy Now'
11 __author__ = 'unkn0wn'
12 description = '''Philosophy Now is a lively magazine for everyone
13 interested in ideas. It isn't afraid to tackle all the major questions of
14 life, the universe and everything. Published every two months, it tries to
15 corrupt innocent citizens by convincing them that philosophy can be
16 exciting, worthwhile and comprehensible, and also to provide some enjoyable
17 reading matter for those already ensnared by the muse, such as philosophy
18 students and academics.'''
19 language = 'en'
20 use_embedded_content = False
21 no_stylesheets = True
22 remove_javascript = True
23 remove_attributes = ['height', 'width', 'style']
24 encoding = 'utf-8'
25 ignore_duplicate_articles = {'url'}
26 masthead_url = 'https://philosophynow.org/media/images/regulars/logoStructuredData.png'
27
28 keep_only_tags = [classes('article_page')]
29 remove_tags = [dict(name='div', attrs={'id': 'welcome_box'})]
30 extra_css = '''
31 img {display:block; margin:0 auto;}
32 .articleImageCaption { font-size:small; text-align:center; }
33 em, blockquote { color:#202020; }
34 '''
35
36 recipe_specific_options = {'issue': {'short': 'Enter the Issue Number you want to download ', 'long': 'For example, 136'}}
37
38 def parse_index(self):
39 soup = self.index_to_soup('https://philosophynow.org/')
40 div = soup.find('div', attrs={'id': 'aside_issue_cover'})
41 url = 'https://philosophynow.org' + div.find('a', href=True)['href']
42
43 d = self.recipe_specific_options.get('issue')
44 if d and isinstance(d, str):
45 url = 'https://philosophynow.org/issues/' + d
46
47 soup = self.index_to_soup(url)
48
49 div = soup.find('div', attrs={'id': 'issue_contents_cover_div'})
50 cov_url = div.find('img', src=True)['src']
51 self.cover_url = 'https://philosophynow.org' + cov_url
52 self.timefmt = ' [' + self.tag_to_string(soup.find('h1')) + ']'
53
54 feeds = OrderedDict()
55
56 for h2 in soup.findAll('h2', attrs={'class': 'article_list_title'}):
57 articles = []
58 a = h2.find('a', href=True)
59 url = a['href']
60 url = 'https://philosophynow.org' + url
61 title = self.tag_to_string(a)
62 des = h2.find_next_sibling('p')
63 if des:
64 desc = self.tag_to_string(des)
65 h3 = h2.find_previous_sibling('h3')
66 section_title = self.tag_to_string(h3).title()
67 self.log('\t', title)
68 self.log('\t', desc)
69 self.log('\t\t', url)
70 articles.append({'title': title, 'url': url, 'description': desc})
71
72 if articles:
73 if section_title not in feeds:
74 feeds[section_title] = []
75 feeds[section_title] += articles
76 ans = list(feeds.items())
77 return ans
78
79 # PN changes the content it delivers based on cookies, so the
80 # following ensures that we send no cookies
81 def get_browser(self, *args, **kwargs):
82 return self
83
84 def clone_browser(self, *args, **kwargs):
85 return self.get_browser()
86
87 def open_novisit(self, *args, **kwargs):
88 br = browser(verify_ssl_certificates=False)
89 return br.open_novisit(*args, **kwargs)
90
91 open = open_novisit