mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
update India Today
This commit is contained in:
parent
320dff52a6
commit
3e6d7dd057
@ -7,17 +7,27 @@ class IndiaToday(BasicNewsRecipe):
|
|||||||
__author__ = 'unkn0wn'
|
__author__ = 'unkn0wn'
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
use_embedded_content = False
|
use_embedded_content = False
|
||||||
remove_attributes = ['style','height','width']
|
remove_attributes = ['style', 'height', 'width']
|
||||||
ignore_duplicate_articles = {'url'}
|
ignore_duplicate_articles = {'url'}
|
||||||
extra_css = '[itemprop^="description"] {font-size: small; font-style: italic;}'
|
extra_css = '[itemprop^="description"] {font-size: small; font-style: italic;}'
|
||||||
description = (
|
description = (
|
||||||
'India’s Most Reputed, Credible and Popular news magazine.'
|
'India’s Most Reputed, Credible and Popular news magazine.'
|
||||||
' Read the most preferred magazine of 9.5 million Indians to access highly researched and unbiased content.')
|
' Read the most preferred magazine of 9.5 million Indians to access highly researched and unbiased content.'
|
||||||
|
)
|
||||||
masthead_url = 'https://akm-img-a-in.tosshub.com/sites/all/themes/itg/logo.png'
|
masthead_url = 'https://akm-img-a-in.tosshub.com/sites/all/themes/itg/logo.png'
|
||||||
|
|
||||||
|
extra_css = '''
|
||||||
|
.body_caption{font-size:small;}
|
||||||
|
.image-alt{font-size:small;}
|
||||||
|
'''
|
||||||
|
|
||||||
def get_cover_url(self):
|
def get_cover_url(self):
|
||||||
soup = self.index_to_soup('https://www.readwhere.com/magazine/the-india-today-group/India-Today/1154')
|
soup = self.index_to_soup(
|
||||||
for citem in soup.findAll('meta', content=lambda s: s and s.endswith('/magazine/300/new')):
|
'https://www.readwhere.com/magazine/the-india-today-group/India-Today/1154'
|
||||||
|
)
|
||||||
|
for citem in soup.findAll(
|
||||||
|
'meta', content=lambda s: s and s.endswith('/magazine/300/new')
|
||||||
|
):
|
||||||
return citem['content'].replace('300', '600')
|
return citem['content'].replace('300', '600')
|
||||||
|
|
||||||
keep_only_tags = [
|
keep_only_tags = [
|
||||||
@ -32,32 +42,40 @@ class IndiaToday(BasicNewsRecipe):
|
|||||||
section = None
|
section = None
|
||||||
sections = {}
|
sections = {}
|
||||||
|
|
||||||
for tag in soup.findAll('div', attrs={'class':['magazin-top-left', 'section-ordering']}):
|
for tag in soup.findAll(
|
||||||
|
'div', attrs={'class': ['magazin-top-left', 'section-ordering']}
|
||||||
|
):
|
||||||
sec = tag.find('span')
|
sec = tag.find('span')
|
||||||
section = self.tag_to_string(sec)
|
section = self.tag_to_string(sec)
|
||||||
self.log(section)
|
self.log(section)
|
||||||
sections[section] = []
|
sections[section] = []
|
||||||
|
|
||||||
for a in tag.findAll('a', href=lambda x: x and x.startswith(("/magazine/cover-story/story/", "https://www.indiatoday.in/magazine/"))):
|
for a in tag.findAll(
|
||||||
|
'a',
|
||||||
|
href=lambda x: x and x.startswith((
|
||||||
|
"/magazine/cover-story/story/",
|
||||||
|
"https://www.indiatoday.in/magazine/"
|
||||||
|
))
|
||||||
|
):
|
||||||
url = a['href']
|
url = a['href']
|
||||||
if url.startswith('https'):
|
if url.startswith('https'):
|
||||||
url = url
|
url = url
|
||||||
else:
|
else:
|
||||||
url = 'https://www.indiatoday.in' + url
|
url = 'https://www.indiatoday.in' + url
|
||||||
title = self.tag_to_string(a)
|
title = self.tag_to_string(a).strip()
|
||||||
empty = " "
|
if not url or not title:
|
||||||
if title is empty:
|
continue
|
||||||
url = ''
|
|
||||||
self.log('\t', title)
|
self.log('\t', title)
|
||||||
self.log('\t\t', url)
|
self.log('\t\t', url)
|
||||||
sections[section].append({
|
sections[section].append({'title': title, 'url': url})
|
||||||
'title': title,
|
|
||||||
'url': url})
|
|
||||||
|
|
||||||
def sort_key(x):
|
def sort_key(x):
|
||||||
section = x[0]
|
section = x[0]
|
||||||
try:
|
try:
|
||||||
return ('EDITOR\'S NOTE', 'Cover Story', 'The Big Story', 'Upfront', 'NATION', 'INTERVIEW').index(section)
|
return (
|
||||||
|
'EDITOR\'S NOTE', 'Cover Story', 'The Big Story', 'Upfront',
|
||||||
|
'NATION', 'INTERVIEW'
|
||||||
|
).index(section)
|
||||||
except Exception:
|
except Exception:
|
||||||
return 99999999
|
return 99999999
|
||||||
|
|
||||||
@ -66,6 +84,15 @@ class IndiaToday(BasicNewsRecipe):
|
|||||||
def preprocess_raw_html(self, raw_html, url):
|
def preprocess_raw_html(self, raw_html, url):
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||||
soup = BeautifulSoup(raw_html)
|
soup = BeautifulSoup(raw_html)
|
||||||
|
for div in soup.findAll('div', attrs={'id': 'premium_content_data'}):
|
||||||
|
div.extract()
|
||||||
|
for tv in soup.findAll(
|
||||||
|
'div',
|
||||||
|
attrs={
|
||||||
|
'class': ['live-tv-ico', 'sendros', 'live-tv-ico-st', 'sendros-st']
|
||||||
|
}
|
||||||
|
):
|
||||||
|
tv.extract()
|
||||||
for script in soup.findAll('script'):
|
for script in soup.findAll('script'):
|
||||||
script.extract()
|
script.extract()
|
||||||
for style in soup.findAll('style'):
|
for style in soup.findAll('style'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user