Debian Codegraph @

recipes/epoch_times.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3 from calibre.web.feeds.news import BasicNewsRecipe, classes
4
5
6 class EpochTimes(BasicNewsRecipe):
7 title = 'The Epoch Times'
8 __author__ = 'Kovid Goyal'
9 description = 'US general news'
10 language = 'en'
11 encoding = 'utf-8'
12 oldest_article = 1.2
13 max_articles_per_feed = 20
14 ignore_duplicate_articles = {'url'}
15 remove_attributes = ['height', 'width', 'style']
16 remove_empty_feeds = True
17 no_stylesheets = True
18 resolve_internal_links = True
19 masthead_url = 'https://epochtimes-ny.newsmemory.com/eeLayout/epochtimes/1.0.a/images/webapp/banner.png'
20 extra_css = '.post_caption, .text-sm, .uppercase {font-size:small;}'
21
22 recipe_specific_options = {
23 'days': {
24 'short': 'Oldest article to download from this news source. In days ',
25 'long': 'For example, 0.5, gives you articles from the past 12 hours',
26 'default': str(oldest_article),
27 }
28 }
29
30 def __init__(self, *args, **kwargs):
31 BasicNewsRecipe.__init__(self, *args, **kwargs)
32 d = self.recipe_specific_options.get('days')
33 if d and isinstance(d, str):
34 self.oldest_article = float(d)
35
36 keep_only_tags = [dict(name='article')]
37 remove_tags = [
38 classes('print:hidden h-header shortcode aspect-square'),
39 dict(name=['button', 'svg']),
40 dict(name='img', attrs={'src': lambda x: x and x.endswith('svg')}),
41 ]
42
43 # feeds can be found at https://www.theepochtimes.com/rssfeeds
44 feeds = [
45 ('Special Series', 'https://feed.theepochtimes.com/health/special-series/feed'),
46 ('US', 'https://feed.theepochtimes.com/us/feed'),
47 ('China News', 'https://feed.theepochtimes.com/china/feed'),
48 ('World', 'https://feed.theepochtimes.com/world/feed'),
49 ('Opinion', 'https://feed.theepochtimes.com/opinion/feed'),
50 ('Business & Markets', 'https://feed.theepochtimes.com/business/feed'),
51 ('Science', 'https://feed.theepochtimes.com/science/feed'),
52 ('Tech', 'https://feed.theepochtimes.com/tech/feed'),
53 ('Health & Wellness', 'https://feed.theepochtimes.com/wellness/feed'),
54 ('Epoch Taste', 'https://feed.theepochtimes.com/epoch-taste/feed'),
55 ('Entertainment', 'https://feed.theepochtimes.com/entertainment/feed'),
56 ]
57
58 def preprocess_html(self, soup):
59 for img in soup.findAll('img', attrs={'data-src': True}):
60 img['src'] = img['data-src']
61 for fig_c in soup.findAll('figcaption'):
62 fig_c['class'] = 'post_caption'
63 return soup