mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Frontline and Outlook Magazine
This commit is contained in:
parent
c94e0b719f
commit
c0d533f7ec
@ -1,7 +1,6 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
||||||
|
|
||||||
|
|
||||||
class Frontline(BasicNewsRecipe):
|
class Frontline(BasicNewsRecipe):
|
||||||
title = u'Frontline'
|
title = u'Frontline'
|
||||||
__author__ = 'unkn0wn'
|
__author__ = 'unkn0wn'
|
||||||
@ -16,18 +15,21 @@ class Frontline(BasicNewsRecipe):
|
|||||||
remove_attributes = ['height', 'width']
|
remove_attributes = ['height', 'width']
|
||||||
resolve_internal_links = True
|
resolve_internal_links = True
|
||||||
extra_css = '''
|
extra_css = '''
|
||||||
.overline{ font-size:small; color:#404040; }
|
.environment, .publish-time, .author { font-size:small; color:#404040; }
|
||||||
.person-name { font-size:small; font-weight:bold; }
|
.caption { font-size:small; text-align:center; }
|
||||||
.lead-img-caption, .caption-cont { font-size:small; text-align:center; }
|
img { display:block; margin:0 auto; }
|
||||||
|
.question {font-weight:bold;}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
keep_only_tags = [
|
keep_only_tags = [
|
||||||
classes('article')
|
dict(name='div', attrs={'class':'container article-section'})
|
||||||
]
|
]
|
||||||
|
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
classes('shareicon-article articleBottomLine secheader mobilesocialicons'),
|
classes(
|
||||||
dict(name='h2', attrs={'class':'title'})
|
'breadcrumb comments-shares share-page article-video '
|
||||||
|
'referpara slide-mobile title-patch hide-mobile related-stories'
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
def preprocess_html(self, soup):
|
def preprocess_html(self, soup):
|
||||||
@ -36,11 +38,11 @@ class Frontline(BasicNewsRecipe):
|
|||||||
source = img.findPrevious('source', srcset=True)
|
source = img.findPrevious('source', srcset=True)
|
||||||
img.extract()
|
img.extract()
|
||||||
if source:
|
if source:
|
||||||
source['src'] = source['srcset']
|
source['src'] = source['srcset'].replace('_320','_1200')
|
||||||
source.name = 'img'
|
source.name = 'img'
|
||||||
else:
|
else:
|
||||||
img['src'] = img['data-original']
|
img['src'] = img['data-original']
|
||||||
for cap in soup.findAll(**classes('caption-cont')):
|
for cap in soup.findAll(**classes('caption')):
|
||||||
cap.name = 'figcaption'
|
cap.name = 'figcaption'
|
||||||
return soup
|
return soup
|
||||||
|
|
||||||
@ -50,30 +52,32 @@ class Frontline(BasicNewsRecipe):
|
|||||||
return soup
|
return soup
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
soup = self.index_to_soup('https://frontline.thehindu.com/magazine/')
|
soup = self.index_to_soup('https://frontline.thehindu.com/current-issue/')
|
||||||
issue = soup.find(**classes('sptar-archive-item')).find('a')['href']
|
|
||||||
self.log(issue)
|
if cover := soup.find('div', attrs={'class':'magazine'}):
|
||||||
soup = self.index_to_soup(issue)
|
self.cover_url = cover.find(**classes('sptar-image')).img['data-original'].replace('_320', '_1200')
|
||||||
time = soup.find(**classes('date')).findNext('h3')
|
self.log('Cover ', self.cover_url)
|
||||||
if time:
|
if desc := cover.find(**classes('sub-text')):
|
||||||
self.timefmt = ' ' + self.tag_to_string(time)
|
self.description = self.tag_to_string(desc)
|
||||||
self.log('Downloading Issue:', self.timefmt)
|
|
||||||
self.cover_url = soup.find(**classes('sptar-cover-item')).find('img')['data-original'].replace('FREE_320', 'FREE_810')
|
|
||||||
feeds_dict = defaultdict(list)
|
feeds_dict = defaultdict(list)
|
||||||
for div in soup.findAll('div', attrs={'class':'brief-list-item'}):
|
|
||||||
a = div.find(**classes('brief-title')).find('a')
|
mag = soup.find(**classes('section-magazine'))
|
||||||
|
for div in mag.findAll('div', attrs={'class':'content'}):
|
||||||
|
a = div.find(**classes('title')).find('a')
|
||||||
url = a['href']
|
url = a['href']
|
||||||
title = self.tag_to_string(a)
|
title = self.tag_to_string(a)
|
||||||
section = 'Articles'
|
section = 'Articles'
|
||||||
cat = div.find(**classes('brief-cat'))
|
if cat := div.find(**classes('label')):
|
||||||
if cat:
|
|
||||||
section = self.tag_to_string(cat)
|
section = self.tag_to_string(cat)
|
||||||
desc = ''
|
desc = ''
|
||||||
art = div.find(**classes('artbody'))
|
|
||||||
if art:
|
if art := div.find(**classes('sub-text')):
|
||||||
desc = self.tag_to_string(art)
|
desc = self.tag_to_string(art)
|
||||||
|
if auth := div.find(**classes('author')):
|
||||||
|
desc = self.tag_to_string(auth) + ' | ' + desc
|
||||||
if not url or not title:
|
if not url or not title:
|
||||||
continue
|
continue
|
||||||
self.log(section, '\n\t', title, '\n\t', desc, '\n\t\t', url)
|
self.log(section, '\n\t', title, '\n\t', desc, '\n\t\t', url)
|
||||||
feeds_dict[section].append({"title": title, "url": url})
|
feeds_dict[section].append({"title": title, "url": url, "description": desc})
|
||||||
return [(section, articles) for section, articles in feeds_dict.items()]
|
return [(section, articles) for section, articles in feeds_dict.items()]
|
@ -32,6 +32,9 @@ class outlook(BasicNewsRecipe):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_browser(self):
|
||||||
|
return BasicNewsRecipe.get_browser(self, user_agent='common_words/based')
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
soup = self.index_to_soup('https://www.outlookindia.com/magazine')
|
soup = self.index_to_soup('https://www.outlookindia.com/magazine')
|
||||||
div = soup.find('div', attrs={'class':'wrapper'})
|
div = soup.find('div', attrs={'class':'wrapper'})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user