| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 4 |
|
| 5 |
|
| 6 |
class outlook(BasicNewsRecipe): |
| 7 |
title = 'Outlook Magazine' |
| 8 |
__author__ = 'unkn0wn' |
| 9 |
description = ( |
| 10 |
'Outlook covers the latest India news, analysis, business news and long-form stories on culture,' |
| 11 |
" money market and personal finance. Read India's best online magazine." |
| 12 |
) |
| 13 |
language = 'en_IN' |
| 14 |
use_embedded_content = False |
| 15 |
no_stylesheets = True |
| 16 |
remove_javascript = True |
| 17 |
remove_attributes = ['height', 'width', 'style'] |
| 18 |
ignore_duplicate_articles = {'url'} |
| 19 |
resolve_internal_links = True |
| 20 |
masthead_url = 'https://images.assettype.com/outlookindia/2024-02/96fb06ce-1cc8-410e-ad6c-da4de57405f8/Outlook.svg' |
| 21 |
extra_css = ''' |
| 22 |
.subcap-story {font-style:italic; color:#202020;} |
| 23 |
.story-slug, .article-name-date {font-size:small; color:#404040;} |
| 24 |
.main-img-div, .sb-image {font-size:small; text-align:center;} |
| 25 |
em { color:#202020; } |
| 26 |
''' |
| 27 |
browser_type = 'webengine' |
| 28 |
|
| 29 |
keep_only_tags = [ |
| 30 |
# classes('story-slug story-title subcap-story article-name-date main-img-div sb-article') |
| 31 |
classes('story-slug story-title subcap-story article-name-date w-93') |
| 32 |
] |
| 33 |
|
| 34 |
remove_tags = [ |
| 35 |
dict(name='svg'), |
| 36 |
dict( |
| 37 |
name='a', |
| 38 |
attrs={'href': lambda x: x and x.startswith('https://www.whatsapp.com/')}, |
| 39 |
), |
| 40 |
classes('ads-box info-img-absolute mobile-info-id story-dec-time-mobile sb-also-read ads-box1 story-mag-issue-section'), |
| 41 |
] |
| 42 |
|
| 43 |
recipe_specific_options = { |
| 44 |
'date': { |
| 45 |
'short': 'The date of the edition to download (DD-Month-YYYY format)', |
| 46 |
'long': 'For example, 10-june-2024', |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
def parse_index(self): |
| 51 |
self.log('try again and again\n***\nif this recipe fails, report it on: https://www.mobileread.com/forums/forumdisplay.php?f=228\n***\n') |
| 52 |
|
| 53 |
d = self.recipe_specific_options.get('date') |
| 54 |
if d and isinstance(d, str): |
| 55 |
url = 'https://www.outlookindia.com/magazine/' + d |
| 56 |
else: |
| 57 |
soup = self.index_to_soup('https://www.outlookindia.com/magazine') |
| 58 |
a = soup.find('a', attrs={'aria-label': 'magazine-cover-image'}) |
| 59 |
url = a['href'] |
| 60 |
|
| 61 |
self.log('Downloading issue:', url) |
| 62 |
|
| 63 |
soup = self.index_to_soup(url) |
| 64 |
cov = soup.find(attrs={'aria-label': 'magazine-cover-image'}) |
| 65 |
self.cover_url = cov.img['src'].split('?')[0] |
| 66 |
summ = soup.find(attrs={'data-test-id': 'magazine-summary'}) |
| 67 |
if summ: |
| 68 |
self.description = self.tag_to_string(summ) |
| 69 |
tme = soup.find(attrs={'class': 'arr__timeago'}) |
| 70 |
if tme: |
| 71 |
self.timefmt = ' [' + self.tag_to_string(tme).split('-')[-1].strip() + ']' |
| 72 |
|
| 73 |
ans = [] |
| 74 |
|
| 75 |
for div in soup.findAll(attrs={'class': 'article-heading-two'}): |
| 76 |
a = div.a |
| 77 |
url = a['href'] |
| 78 |
title = self.tag_to_string(a) |
| 79 |
desc = '' |
| 80 |
p = div.find_next_sibling('p', attrs={'class': lambda x: x and 'article-desc' in x.split()}) |
| 81 |
if p: |
| 82 |
desc = self.tag_to_string(p) |
| 83 |
auth = div.find_next_sibling('p', attrs={'class': 'author'}) |
| 84 |
if auth: |
| 85 |
desc = self.tag_to_string(auth) + ' | ' + desc |
| 86 |
self.log('\t', title) |
| 87 |
self.log('\t', desc) |
| 88 |
self.log('\t\t', url) |
| 89 |
ans.append({'title': title, 'url': url, 'description': desc}) |
| 90 |
return [('Articles', ans)] |
| 91 |
|
| 92 |
def preprocess_html(self, soup): |
| 93 |
if sub := soup.find(**classes('subcap-story')): |
| 94 |
sub.name = 'p' |
| 95 |
for h2 in soup.findAll(['h2', 'h3']): |
| 96 |
h2.name = 'h4' |
| 97 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 98 |
img['src'] = img['data-src'].split('?')[0] + '?w=600' |
| 99 |
return soup |