Debian Codegraph @

recipes/outlook_business_magazine.recipe

raw
1 import json
2 import re
3
4 from calibre.web.feeds.news import BasicNewsRecipe, classes
5
6
7 class outlook(BasicNewsRecipe):
8 title = 'Outlook Business Magazine'
9 __author__ = 'unkn0wn'
10 description = (
11 'Outlook Business (Monthly) Magazine produces Business, Market, Startup and Leadership'
12 ' content that is differentiated to offer a deeper understanding of trends shaping India. Read to hone your leadership skills.'
13 )
14 language = 'en_IN'
15 use_embedded_content = False
16 no_stylesheets = True
17 remove_javascript = True
18 remove_attributes = ['height', 'width', 'style']
19 ignore_duplicate_articles = {'url'}
20 masthead_url = 'https://imgnew.outlookindia.com/uploadimage/library/free_files/jpg/logo_2022_04_30_092331.jpg'
21 extra_css = '.author{font-size:small;}'
22
23 def parse_index(self):
24 soup = self.index_to_soup('https://www.outlookbusiness.com/magazine/')
25 div = soup.find('div', attrs={'class': 'SplWapper'})
26 url = div.find('a', href=True)['href']
27 self.cover_url = div.find('img', srcset=True)['srcset']
28 self.timefmt = '[' + self.tag_to_string(div.find('h6')) + ']'
29 soup = self.index_to_soup('https://www.outlookbusiness.com' + url)
30 ans = []
31
32 for section in soup.findAll(**classes('category-banner-content')):
33 p = section.find('p', attrs={'class': lambda x: x and x.startswith('styled__Content')})
34 desc = self.tag_to_string(p)
35 head = section.find('p', attrs={'class': lambda x: x and x.startswith('styled__Heading')})
36 title = self.tag_to_string(head)
37 a = p.findParent('a', href=True)['href']
38 if a.startswith('/'):
39 url = 'https://www.outlookbusiness.com' + a
40 self.log('\t', title, '\n\t', desc, '\n\t\t', url)
41 ans.append({'title': title, 'description': desc, 'url': url})
42 return [('Articles', ans)]
43
44 def preprocess_raw_html(self, raw, *a):
45 m = re.search(r'id="__NEXT_DATA__" type="application/json">', raw)
46 raw = raw[m.start() :]
47 raw = raw.split('>', 1)[1]
48 data = json.JSONDecoder().raw_decode(raw)[0]
49 data = data['props']['initialState']['dashboard']['ARTICLE_POST_DETAIL_API']['data']['article_data']
50 title = data['title']
51 body = data['description']
52 cat = desc = image = author = ''
53 if 'category_name' in data:
54 try:
55 cat = data['category_name']
56 except Exception:
57 cat = ''
58 if 'excerpt' in data:
59 desc = '<h4>' + data['excerpt'] + '</h4>'
60 if 'author' in data:
61 try:
62 author = data['author'][0]['name']
63 except Exception:
64 author = ''
65 if 'images' in data:
66 try:
67 image = '<p><img src="{}">'.format(data['images'][0]['image'])
68 except Exception:
69 image = ''
70 html = '<html><body>' + cat + '<h1>' + title + '</h1>' + desc + '<div class="author">' + author + '</div>' + image + body
71 return html