Debian Codegraph @

recipes/orfonline.recipe

raw
1 #!/usr/bin/env python
2 from datetime import datetime, timedelta
3
4 from calibre.utils.date import parse_date
5 from calibre.web.feeds.news import BasicNewsRecipe, classes
6
7
8 class ORF(BasicNewsRecipe):
9 title = 'Observer Research Foundation'
10 description = (
11 'Set up in 1990, ORF seeks to lead and aid policy thinking towards building a strong and prosperous India'
12 ' in a fair and equitable world. It helps discover and inform India’s choices, and carries Indian voices '
13 'and ideas to forums shaping global debates.'
14 )
15 language = 'en_IN'
16 __author__ = 'unkn0wn'
17 encoding = 'utf-8'
18 no_stylesheets = True
19 remove_javascript = True
20 masthead_url = 'https://www.orfonline.org/wp-content/uploads/2015/09/Logo_ORF_JPEG.jpg'
21 remove_attributes = ['style', 'height', 'width']
22 ignore_duplicate_articles = {'url', 'title'}
23 oldest_article = 7
24 simultaneous_downloads = 1
25
26 recipe_specific_options = {
27 'days': {
28 'short': 'Oldest article to download from this news source. In days ',
29 'long': 'For example, 0.5, gives you articles from the past 12 hours',
30 'default': str(oldest_article),
31 }
32 }
33
34 def __init__(self, *args, **kwargs):
35 BasicNewsRecipe.__init__(self, *args, **kwargs)
36 d = self.recipe_specific_options.get('days')
37 if d and isinstance(d, str):
38 self.oldest_article = float(d)
39
40 extra_css = '''
41 img {display:block; margin:0 auto;}
42 .report-slider, .author_panel {font-size:small; color:#404040;}
43 .report {font-size:small; font-weight:bold;}
44 .excert-italic, .recent-block-people {font-style:italic; color:#202020;}
45 blockquote, em {color:#202020;}
46 .espert_speak_panel {font-size:small;}
47 '''
48
49 def get_browser(self):
50 return BasicNewsRecipe.get_browser(self, user_agent='common_words/based')
51
52 resolve_internal_links = True
53 remove_empty_feeds = True
54
55 keep_only_tags = [dict(name='h1'), classes('author_panel espert_speak_panel expert_panel_content')]
56 remove_tags = [classes('social socialshare comment-area-section telegramhtml post-tag research-prev research-next col-md-4 button_group sharethis-p tags')]
57
58 def parse_index(self):
59 index = 'https://www.orfonline.org'
60 secs = [
61 ('Expert Speak', '/expert-speak'),
62 ('Young Voices', '/expert-speak-category/young-voices'),
63 ('Commentary', '/content-type/commentary'),
64 ('Issue Briefs', '/content-type/issue-briefs'),
65 ('Books', '/content-type/books'),
66 ('Special Reports', '/content-type/special-reports'),
67 ]
68
69 feeds = []
70
71 for x, y in secs:
72 section = x
73 self.log(section)
74
75 articles = []
76
77 soup = self.index_to_soup(index + y)
78 for a in soup.findAll('a', attrs={'href': True}):
79 if not a.find('h3'):
80 continue
81 div = a.find_previous_sibling(attrs={'class': 'topic_story'})
82 if div:
83 if div.find(**classes('show_date')):
84 date = parse_date(self.tag_to_string(div.find(**classes('show_date')))).replace(tzinfo=None)
85 if (datetime.now() - date) > timedelta(self.oldest_article):
86 self.log(' Skipping ', self.tag_to_string(a))
87 continue
88 url = a['href']
89 title = self.tag_to_string(a)
90 desc = ''
91 if a.find_next_sibling('p'):
92 desc = self.tag_to_string(a.find_next_sibling('p'))
93 if a.find_next_sibling(attrs={'class': 'author_name'}):
94 desc = self.tag_to_string(a.find_next_sibling(attrs={'class': 'author_name'})) + ' | ' + desc
95 self.log('\t', title, '\n\t', desc, '\n\t\t', url)
96 articles.append({'title': title, 'url': url, 'description': desc})
97 if articles:
98 feeds.append((section, articles))
99 return feeds