mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Indian Express Print Edition by unkn0wn
This commit is contained in:
parent
8c88a4b306
commit
89682efc85
113
recipes/indian_express_print_edition.recipe
Normal file
113
recipes/indian_express_print_edition.recipe
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
|
class IndianExpressPrint(BasicNewsRecipe):
|
||||||
|
title = u'Indian Express | Print Edition'
|
||||||
|
language = 'en_IN'
|
||||||
|
__author__ = 'unkn0wn'
|
||||||
|
masthead_url = 'https://indianexpress.com/wp-content/themes/indianexpress/images/indian-express-logo-n.svg'
|
||||||
|
no_stylesheets = True
|
||||||
|
use_embedded_content = False
|
||||||
|
remove_attributes = ['style', 'height', 'width']
|
||||||
|
ignore_duplicate_articles = {'url'}
|
||||||
|
extra_css = '''
|
||||||
|
#storycenterbyline {font-size:small;}
|
||||||
|
#img-cap {font-size:small;}
|
||||||
|
blockquote{text-align:center; color:#404040;}
|
||||||
|
em{font-style:italic; color:#808080;}
|
||||||
|
#sub-d{color:#202020; font-style:italic;}
|
||||||
|
.ie-authorbox{font-size:small;}
|
||||||
|
'''
|
||||||
|
resolve_internal_links = True
|
||||||
|
remove_empty_feeds = True
|
||||||
|
|
||||||
|
keep_only_tags = [classes('heading-part full-details')]
|
||||||
|
remove_tags = [
|
||||||
|
dict(name='div', attrs={'id': 'ie_story_comments'}),
|
||||||
|
dict(name='div', attrs={'class': lambda x: x and 'related-widget' in x}),
|
||||||
|
dict(
|
||||||
|
name='img',
|
||||||
|
attrs={
|
||||||
|
'src':
|
||||||
|
'https://images.indianexpress.com/2021/06/explained-button-300-ie.jpeg'
|
||||||
|
}
|
||||||
|
),
|
||||||
|
dict(
|
||||||
|
name='a',
|
||||||
|
attrs={
|
||||||
|
'href':
|
||||||
|
'https://indianexpress.com/section/explained/?utm_source=newbanner'
|
||||||
|
}
|
||||||
|
),
|
||||||
|
dict(
|
||||||
|
name='img',
|
||||||
|
attrs={
|
||||||
|
'src':
|
||||||
|
'https://images.indianexpress.com/2021/06/opinion-button-300-ie.jpeg'
|
||||||
|
}
|
||||||
|
),
|
||||||
|
dict(
|
||||||
|
name='a',
|
||||||
|
attrs={
|
||||||
|
'href':
|
||||||
|
'https://indianexpress.com/section/opinion/?utm_source=newbanner'
|
||||||
|
}
|
||||||
|
),
|
||||||
|
classes(
|
||||||
|
'share-social appstext ie-int-campign-ad ie-breadcrumb custom_read_button unitimg copyright'
|
||||||
|
' storytags pdsc-related-modify news-guard premium-story append_social_share'
|
||||||
|
' digital-subscriber-only h-text-widget ie-premium ie-first-publish adboxtop adsizes immigrationimg'
|
||||||
|
'next-story-wrap ie-ie-share next-story-box brand-logo quote_section ie-customshare'
|
||||||
|
' custom-share o-story-paper-quite ie-network-commenting'
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
def parse_index(self):
|
||||||
|
soup = self.index_to_soup('https://indianexpress.com/todays-paper/')
|
||||||
|
feeds_dict = defaultdict(list)
|
||||||
|
for div in soup.findAll('div', attrs={'class':['lead-story', 'section']}):
|
||||||
|
for a in div.findAll('a', attrs={'href':lambda x: x and x.startswith('https://indianexpress.com/article/')}):
|
||||||
|
if not a.find('img'):
|
||||||
|
url = a['href']
|
||||||
|
title = self.tag_to_string(a)
|
||||||
|
section = 'Front Page'
|
||||||
|
str = a.findParent('strong')
|
||||||
|
if str:
|
||||||
|
span = str.find_previous_sibling('span')
|
||||||
|
if span:
|
||||||
|
section = self.tag_to_string(span)
|
||||||
|
# if 'City' in section:
|
||||||
|
# url = ''
|
||||||
|
if not url or not title:
|
||||||
|
continue
|
||||||
|
self.log(section, '\n\t', title, '\n\t\t', url)
|
||||||
|
feeds_dict[section].append({"title": title, "url": url})
|
||||||
|
return [(section, articles) for section, articles in feeds_dict.items()]
|
||||||
|
|
||||||
|
def get_cover_url(self):
|
||||||
|
soup = self.index_to_soup(
|
||||||
|
'https://www.magzter.com/IN/The-Indian-Express-Ltd./The-Indian-Express-Mumbai/Newspaper/'
|
||||||
|
)
|
||||||
|
for citem in soup.findAll(
|
||||||
|
'meta', content=lambda s: s and s.endswith('view/3.jpg')
|
||||||
|
):
|
||||||
|
return citem['content']
|
||||||
|
|
||||||
|
def preprocess_html(self, soup):
|
||||||
|
h2 = soup.find('h2')
|
||||||
|
if h2:
|
||||||
|
h2.name = 'p'
|
||||||
|
h2['id'] = 'sub-d'
|
||||||
|
for span in soup.findAll(
|
||||||
|
'span', attrs={'class': ['ie-custom-caption', 'custom-caption']}
|
||||||
|
):
|
||||||
|
span['id'] = 'img-cap'
|
||||||
|
for img in soup.findAll('img'):
|
||||||
|
noscript = img.findParent('noscript')
|
||||||
|
if noscript is not None:
|
||||||
|
lazy = noscript.findPreviousSibling('img')
|
||||||
|
if lazy is not None:
|
||||||
|
lazy.extract()
|
||||||
|
noscript.name = 'div'
|
||||||
|
return soup
|
Loading…
x
Reference in New Issue
Block a user