| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
from collections import defaultdict |
| 4 |
|
| 5 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 6 |
|
| 7 |
|
| 8 |
class Frontline(BasicNewsRecipe): |
| 9 |
title = 'Frontline' |
| 10 |
__author__ = 'unkn0wn' |
| 11 |
description = 'Frontline, the fortnightly English magazine from the stable of The Hindu, has been a distinguished presence in the media world since 1984.' |
| 12 |
language = 'en_IN' |
| 13 |
no_stylesheets = True |
| 14 |
remove_javascript = True |
| 15 |
use_embedded_content = False |
| 16 |
encoding = 'utf-8' |
| 17 |
ignore_duplicate_articles = {'url'} |
| 18 |
masthead_url = 'https://frontline.thehindu.com/theme/images/fl-online/frontline-logo.png' |
| 19 |
remove_attributes = ['height', 'width'] |
| 20 |
resolve_internal_links = True |
| 21 |
extra_css = ''' |
| 22 |
.environment, .publish-time, .author { font-size:small; color:#404040; } |
| 23 |
.caption { font-size:small; text-align:center; } |
| 24 |
img { display:block; margin:0 auto; } |
| 25 |
.question {font-weight:bold;} |
| 26 |
''' |
| 27 |
|
| 28 |
keep_only_tags = [dict(name='div', attrs={'class': 'container article-section'})] |
| 29 |
|
| 30 |
remove_tags = [ |
| 31 |
classes('breadcrumb comments-shares share-page article-video referpara slide-mobile title-patch hide-mobile related-stories'), |
| 32 |
] |
| 33 |
|
| 34 |
def preprocess_html(self, soup): |
| 35 |
for img in soup.findAll('img', attrs={'data-original': True}): |
| 36 |
if img['data-original'].endswith('1x1_spacer.png'): |
| 37 |
source = img.findPrevious('source', srcset=True) |
| 38 |
img.extract() |
| 39 |
if source: |
| 40 |
source['src'] = source['srcset'].replace('_320', '_1200') |
| 41 |
source.name = 'img' |
| 42 |
else: |
| 43 |
img['src'] = img['data-original'] |
| 44 |
for cap in soup.findAll(**classes('caption')): |
| 45 |
cap.name = 'figcaption' |
| 46 |
return soup |
| 47 |
|
| 48 |
def postprocess_html(self, soup, first_fetch): |
| 49 |
for src in soup.findAll('source'): |
| 50 |
src.extract() |
| 51 |
return soup |
| 52 |
|
| 53 |
recipe_specific_options = {'issue': {'short': 'Enter the Issue Number you want to download\n(Volume-Issue format)', 'long': 'For example, 41-12'}} |
| 54 |
|
| 55 |
def parse_index(self): |
| 56 |
issue_url = 'https://frontline.thehindu.com/current-issue/' |
| 57 |
d = self.recipe_specific_options.get('issue') |
| 58 |
if d and isinstance(d, str): |
| 59 |
issue_url = 'https://frontline.thehindu.com/magazine/issue/vol' + d |
| 60 |
|
| 61 |
soup = self.index_to_soup(issue_url) |
| 62 |
|
| 63 |
if cover := soup.find('div', attrs={'class': 'magazine'}): |
| 64 |
self.cover_url = cover.find(**classes('sptar-image')).img['data-original'].replace('SQUARE_80', 'FREE_615') |
| 65 |
self.log('Cover ', self.cover_url) |
| 66 |
if desc := cover.find(**classes('sub-text')): |
| 67 |
self.description = self.tag_to_string(desc) |
| 68 |
|
| 69 |
feeds_dict = defaultdict(list) |
| 70 |
|
| 71 |
mag = soup.find(**classes('current-issue-in-this-issue')) |
| 72 |
for div in mag.findAll('div', attrs={'class': 'content'}): |
| 73 |
a = div.find(**classes('title')).find('a') |
| 74 |
url = a['href'] |
| 75 |
title = self.tag_to_string(a) |
| 76 |
section = 'Articles' |
| 77 |
if cat := div.find(**classes('label')): |
| 78 |
section = self.tag_to_string(cat) |
| 79 |
desc = '' |
| 80 |
|
| 81 |
if art := div.find(**classes('sub-text')): |
| 82 |
desc = self.tag_to_string(art) |
| 83 |
if auth := div.find(**classes('author')): |
| 84 |
desc = self.tag_to_string(auth) + ' | ' + desc |
| 85 |
if not url or not title: |
| 86 |
continue |
| 87 |
self.log(section, '\n\t', title, '\n\t', desc, '\n\t\t', url) |
| 88 |
feeds_dict[section].append({'title': title, 'url': url, 'description': desc}) |
| 89 |
return list(feeds_dict.items()) |