Debian Codegraph @

recipes/rtnews.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3 """
4 rt.com
5 """
6
7 from calibre.web.feeds.news import BasicNewsRecipe, classes
8
9
10 class RT_eng(BasicNewsRecipe):
11 title = 'Russia Today'
12 __author__ = 'unkn0wn'
13 description = '''
14 RT creates news with an edge for viewers who want to Question More. RT covers stories overlooked by the mainstream
15 media, provides alternative perspectives on current affairs, and acquaints international audiences with a Russian
16 viewpoint on major global events.
17 '''
18 publisher = 'Autonomous Nonprofit Organization "TV-Novosti"'
19 category = 'news, politics, economy, finances, Russia, world'
20 oldest_article = 1.2
21 no_stylesheets = True
22 encoding = 'utf-8'
23 ignore_duplicate_articles = {'url', 'title'}
24 use_embedded_content = False
25 remove_empty_feeds = True
26 remove_javascript = True
27 language = 'en'
28 remove_attributes = ['height', 'width', 'style']
29 publication_type = 'newsportal'
30
31 recipe_specific_options = {
32 'days': {
33 'short': 'Oldest article to download from this news source. In days ',
34 'long': 'For example, 0.5, gives you articles from the past 12 hours',
35 'default': str(oldest_article),
36 }
37 }
38
39 def __init__(self, *args, **kwargs):
40 BasicNewsRecipe.__init__(self, *args, **kwargs)
41 d = self.recipe_specific_options.get('days')
42 if d and isinstance(d, str):
43 self.oldest_article = float(d)
44
45 extra_css = '''
46 img {display:block; margin:0 auto;}
47 em { color:#202020; }
48 .date { font-size:small; color:#404040; }
49 .article__summary { font-style:italic; color:#202020; }
50 .media__footer { font-size:small; text-align:center; }
51 '''
52
53 conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language}
54
55 keep_only_tags = [dict(name='div', attrs={'class': 'article'})]
56
57 remove_tags = [
58 dict(name=['meta', 'link', 'svg', 'button', 'style', 'iframe', 'noscript']),
59 classes('update_date_visible breadcrumbs read-more Read-more-text-only article__share article__social-wrapper article__share_bottom'),
60 ]
61
62 feeds = [
63 ('Russia', 'https://www.rt.com/rss/russia/'),
64 ('India', 'https://www.rt.com/rss/india/'),
65 ('Africa', 'https://www.rt.com/rss/africa/'),
66 ('World News', 'https://www.rt.com/rss/news/'),
67 ('Business', 'https://www.rt.com/rss/business/'),
68 ('Opinion', 'https://www.rt.com/rss/op-ed/'),
69 ('Culture', 'https://www.rt.com/rss/pop-culture/'),
70 ('Others', 'https://www.rt.com/rss/'),
71 ]
72
73 def get_article_url(self, article):
74 url = BasicNewsRecipe.get_article_url(self, article)
75 return url.split('?')[0]
76
77 def preprocess_html(self, soup):
78 for img in soup.findAll('img'):
79 srcset = img.find_previous_sibling('source', attrs={'data-srcset': True})
80 if srcset:
81 for x in srcset['data-srcset'].split(','):
82 if '/l/' in x.split()[0].strip():
83 img['src'] = x.split()[0].strip()
84 for src in soup.findAll('source'):
85 src.decompose()
86 return soup