Debian Codegraph @

recipes/firstpost.recipe

raw
1 #!/usr/bin/env python
2 from calibre.web.feeds.news import BasicNewsRecipe, classes
3
4
5 class firstpost(BasicNewsRecipe):
6 title = 'Firstpost'
7 __author__ = 'unkn0wn'
8 description = (
9 'Firstpost.com will serve as a trusted guide to the crush of news and ideas around you.'
10 ' With thoughtful analysis and fearless views our team of editors and writers will track'
11 ' news in India and the world and provide a perspective that is reflective of a changing dynamic.'
12 )
13 no_stylesheets = True
14 use_embedded_content = False
15 encoding = 'utf-8'
16 language = 'en_IN'
17 remove_attributes = ['height', 'width', 'style']
18 masthead_url = 'https://images.firstpost.com/wp-content/uploads/2016/03/FP-Logo.png?impolicy=website&width=600&height=60'
19 max_articles_per_feed = 25
20 remove_empty_feeds = True
21 ignore_duplicate_articles = {'title', 'url'}
22 extra_css = '''
23 .category-name, .author-info { font-size:small; color:#202020; }
24 .wp-caption-text { font-size:small; text-align:center; }
25 '''
26
27 keep_only_tags = [classes('article-sect')]
28
29 remove_tags = [
30 classes('art-rel-articles tags-wrap'),
31 dict(name='svg'),
32 ]
33
34 feeds = []
35
36 sections = [
37 'india',
38 'politics',
39 'opinion',
40 'explainers',
41 'business',
42 'world',
43 'web-stories',
44 'tech',
45 'artandculture',
46 'health',
47 'health-supplement',
48 # 'photos', 'entertainment', 'living', 'education', 'sports', 'firstcricket',
49 ]
50
51 oldest_article = 1.2 # days
52 for sec in sections:
53 a = 'https://www.firstpost.com/rss/{}.xml'
54 feeds.append((sec.capitalize(), a.format(sec)))
55
56 def preprocess_html(self, soup):
57 if h2 := soup.find('h2', attrs={'class': 'category-name'}):
58 h2.name = 'p'
59 if h := soup.find('h2', attrs={'class': 'inner-copy'}):
60 h.name = 'p'
61 for img in soup.findAll('img', attrs={'data-src': True}):
62 img['src'] = img['data-src']
63 return soup