| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 4 |
|
| 5 |
|
| 6 |
class BT(BasicNewsRecipe): |
| 7 |
title = 'Business Today Magazine' |
| 8 |
language = 'en_IN' |
| 9 |
__author__ = 'unkn0wn' |
| 10 |
no_stylesheets = True |
| 11 |
use_embedded_content = False |
| 12 |
remove_javascript = True |
| 13 |
encoding = 'utf-8' |
| 14 |
remove_attributes = ['style', 'height', 'width'] |
| 15 |
ignore_duplicate_articles = {'url'} |
| 16 |
description = ( |
| 17 |
'Business Today is an Indian fortnightly business magazine published by Living Media India Limited,' |
| 18 |
' in publication since 1992. Best downloaded on Sundays, at the end and the middle of the month' |
| 19 |
) |
| 20 |
masthead_url = 'https://akm-img-a-in.tosshub.com/businesstoday/resource/img/logo.png' |
| 21 |
|
| 22 |
keep_only_tags = [ |
| 23 |
classes('story-heading sab-head-tranlate-sec brand-detial-main main-img field--name-body'), |
| 24 |
] |
| 25 |
|
| 26 |
remove_tags = [ |
| 27 |
dict(name=['link', 'meta', 'svg', 'button', 'script']), |
| 28 |
dict(name='a', attrs={'title': 'videos'}), |
| 29 |
classes('tranding-topics-main newsltter-iframe hedlineteg stoybday-ad story-recommended-chunk banner_content'), |
| 30 |
] |
| 31 |
|
| 32 |
recipe_specific_options = {'date': {'short': 'The date of the edition to download (YYYY-MM-DD format)', 'long': 'For example, 2024-07-07'}} |
| 33 |
|
| 34 |
extra_css = ''' |
| 35 |
img {display:block; margin:0 auto;} |
| 36 |
em { color:#202020; } |
| 37 |
.main-img { font-size:small; text-align:center; } |
| 38 |
.summary {font-style:italic; color:#202020; } |
| 39 |
''' |
| 40 |
|
| 41 |
def parse_index(self): |
| 42 |
self.log('\n***\nif this recipe fails, report it on: https://www.mobileread.com/forums/forumdisplay.php?f=228\n***\n') |
| 43 |
|
| 44 |
d = self.recipe_specific_options.get('date') |
| 45 |
if d and isinstance(d, str): |
| 46 |
url = 'https://www.businesstoday.in/magazine/issue/' + d |
| 47 |
else: |
| 48 |
soup = self.index_to_soup('https://www.businesstoday.in') |
| 49 |
a = soup.findAll('a', attrs={'class': 'mag_sld_img'})[1] |
| 50 |
url = a['href'] |
| 51 |
self.cover_url = a.img['data-src'].split('?')[0] |
| 52 |
|
| 53 |
self.log('issue =', url) |
| 54 |
self.timefmt = ' [' + url.split('/')[-1] + ']' |
| 55 |
soup = self.index_to_soup(url) |
| 56 |
section = None |
| 57 |
sections = {} |
| 58 |
|
| 59 |
for tag in soup.findAll('div', attrs={'class': ['magazin-top-left', 'section-ordering']}): |
| 60 |
sec = tag.find(('span', 'h1')) |
| 61 |
section = self.tag_to_string(sec) |
| 62 |
self.log(section) |
| 63 |
sections[section] = [] |
| 64 |
|
| 65 |
for a in tag.findAll('a', href=lambda x: x and x.startswith('https://www.businesstoday.in/magazine/')): |
| 66 |
url = a['href'] |
| 67 |
title = self.tag_to_string(a) |
| 68 |
self.log('\t', title) |
| 69 |
self.log('\t\t', url) |
| 70 |
sections[section].append({'title': title, 'url': url}) |
| 71 |
|
| 72 |
feeds = [] |
| 73 |
|
| 74 |
# Insert feeds in specified order, if available |
| 75 |
|
| 76 |
feedSort = ["Editor's Note", 'Editors note'] |
| 77 |
for i in feedSort: |
| 78 |
if i in sections: |
| 79 |
feeds.append((i, sections[i])) |
| 80 |
|
| 81 |
# Done with the sorted feeds |
| 82 |
|
| 83 |
for i in feedSort: |
| 84 |
sections.pop(i, None) |
| 85 |
|
| 86 |
# Append what is left over... |
| 87 |
|
| 88 |
for i, s in sections.items(): |
| 89 |
feeds.append((i, s)) |
| 90 |
|
| 91 |
return feeds |
| 92 |
|
| 93 |
def preprocess_html(self, soup): |
| 94 |
auth = soup.find(**classes('brand-detial-main')) |
| 95 |
if auth: |
| 96 |
ul = auth.find('ul') |
| 97 |
if ul: |
| 98 |
ul.decompose() |
| 99 |
for vid in soup.findAll('a', attrs={'href': lambda x: x and 'businesstoday.in/videos' in x}): |
| 100 |
vid.decompose() |
| 101 |
summ = soup.find(**classes('summary')) |
| 102 |
if summ: |
| 103 |
h2 = summ.find('h2') |
| 104 |
if h2: |
| 105 |
h2.name = 'p' |
| 106 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 107 |
img['src'] = img['data-src'].split('?')[0] |
| 108 |
return soup |