| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
# from datetime import datetime, timedelta |
| 4 |
|
| 5 |
# from calibre.utils.date import parse_date |
| 6 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 7 |
|
| 8 |
|
| 9 |
class IndianExpress(BasicNewsRecipe): |
| 10 |
title = 'Indian Express' |
| 11 |
language = 'en_IN' |
| 12 |
__author__ = 'unkn0wn' |
| 13 |
oldest_article = 1.15 # days |
| 14 |
encoding = 'utf-8' |
| 15 |
masthead_url = 'https://indianexpress.com/wp-content/themes/indianexpress/images/indian-express-logo-n.svg' |
| 16 |
no_stylesheets = True |
| 17 |
use_embedded_content = False |
| 18 |
remove_attributes = ['style', 'height', 'width'] |
| 19 |
ignore_duplicate_articles = {'url'} |
| 20 |
|
| 21 |
extra_css = ''' |
| 22 |
.ie-custom-caption, .custom-caption, .ie-authorbox, .author-block, .post-info { font-size:small; } |
| 23 |
#storycenterbyline, .author-name-wrap, .top-opinion, .single-author { font-size:small; } |
| 24 |
blockquote { color:#404040; } |
| 25 |
em, #sub-d, .top-description { color:#202020; font-style:italic; } |
| 26 |
img { display:block; margin:0 auto; } |
| 27 |
''' |
| 28 |
|
| 29 |
resolve_internal_links = True |
| 30 |
remove_empty_feeds = True |
| 31 |
|
| 32 |
keep_only_tags = [classes('heading-part full-details top-opinion article-main-head top-description top-image-part story_details')] |
| 33 |
remove_tags = [ |
| 34 |
dict(name='div', attrs={'id': 'ie_story_comments'}), |
| 35 |
dict(name='div', attrs={'class': lambda x: x and 'related-widget' in x}), |
| 36 |
dict(name='img', attrs={'src': lambda x: x and x.endswith('-button-300-ie.jpeg')}), |
| 37 |
dict(name='a', attrs={'href': lambda x: x and x.endswith('/?utm_source=newbanner')}), |
| 38 |
classes( |
| 39 |
'share-social appstext ie-int-campign-ad ie-breadcrumb custom_read_button unitimg copyright ' |
| 40 |
'storytags pdsc-related-modify news-guard premium-story append_social_share ie-int-campign-ad ' |
| 41 |
'digital-subscriber-only h-text-widget ie-premium ie-first-publish adboxtop adsizes immigrationimg ' |
| 42 |
'next-story-wrap ie-ie-share next-story-box brand-logo quote_section ie-customshare osv-ad-class ' |
| 43 |
'custom-share o-story-paper-quite ie-network-commenting audio-player-tts-sec o-story-list subscriber_hide ' |
| 44 |
'author-social author-follow author-img premium_widget_below_article author-block most-read-container ' |
| 45 |
'desktop-full-ad iers_mr_widget ie-newsletter-widget' |
| 46 |
), |
| 47 |
] |
| 48 |
|
| 49 |
recipe_specific_options = { |
| 50 |
'days': { |
| 51 |
'short': 'Oldest article to download from this news source. In days ', |
| 52 |
'long': 'For example, 0.5, gives you articles from the past 12 hours', |
| 53 |
'default': str(oldest_article), |
| 54 |
}, |
| 55 |
'res': { |
| 56 |
'short': 'For hi-res images, select a resolution from the\nfollowing options: 400, 800, 1200, 1600', |
| 57 |
'long': 'This is useful for non e-ink devices.', |
| 58 |
'default': '600', |
| 59 |
}, |
| 60 |
} |
| 61 |
|
| 62 |
def __init__(self, *args, **kwargs): |
| 63 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 64 |
d = self.recipe_specific_options.get('days') |
| 65 |
if d and isinstance(d, str): |
| 66 |
self.oldest_article = float(d) |
| 67 |
|
| 68 |
feeds = [ |
| 69 |
'https://indianexpress.com/section/opinion/feed', |
| 70 |
'https://indianexpress.com/section/delhi-confidential/feed', |
| 71 |
'https://indianexpress.com/section/india/feed', |
| 72 |
'https://indianexpress.com/section/political-pulse/feed', |
| 73 |
'https://indianexpress.com/section/explained/feed', |
| 74 |
'https://indianexpress.com/section/business/feed/', |
| 75 |
'https://indianexpress.com/section/upsc-current-affairs/feed', |
| 76 |
'https://indianexpress.com/section/express-sunday-eye/feed', |
| 77 |
'http://indianexpress.com/section/world/feed', |
| 78 |
'https://indianexpress.com/section/technology/feed', |
| 79 |
'https://indianexpress.com/section/entertainment/feed', |
| 80 |
'https://indianexpress.com/feed', |
| 81 |
] |
| 82 |
|
| 83 |
def get_cover_url(self): |
| 84 |
soup = self.index_to_soup('https://www.readwhere.com/newspaper/indian-express/Nagpur/38726') |
| 85 |
citem = soup.find('meta', attrs={'property': 'og:image'}) |
| 86 |
return citem['content'].replace('300', '600') |
| 87 |
|
| 88 |
def preprocess_html(self, soup): |
| 89 |
width = '600' |
| 90 |
w = self.recipe_specific_options.get('res') |
| 91 |
if w and isinstance(w, str): |
| 92 |
width = w |
| 93 |
if h2 := (soup.find('h2', **classes('synopsis top-description')) or soup.find(attrs={'itemprop': 'description'})): |
| 94 |
h2.name = 'p' |
| 95 |
h2['id'] = 'sub-d' |
| 96 |
for heads in soup.findAll(('h2', 'h3')): |
| 97 |
heads.name = 'h4' |
| 98 |
for span in soup.findAll('span', attrs={'class': ['ie-custom-caption', 'custom-caption']}): |
| 99 |
span['id'] = 'img-cap' |
| 100 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 101 |
img['src'] = img['data-src'].split('?')[0] + '?w=' + width |
| 102 |
# if span := soup.find('span', content=True, attrs={'itemprop': 'dateModified'}): |
| 103 |
# date = parse_date(span['content']).replace(tzinfo=None) |
| 104 |
# today = datetime.now() |
| 105 |
# if (today - date) > timedelta(self.oldest_article): |
| 106 |
# self.abort_article('Skipping old article') |
| 107 |
for img in soup.findAll('img', attrs={'src': True}): |
| 108 |
img['src'] = img['src'].split('?')[0] + '?w=' + width |
| 109 |
return soup |