mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
add inc42.recipe
This commit is contained in:
parent
7c0fae338a
commit
a95132e51b
@ -21,7 +21,7 @@ def get_contents(x):
|
|||||||
return '<blockquote>' + x.get('value', '') + ''.join(map(get_contents, x.get('content'))) + '</blockquote>'
|
return '<blockquote>' + x.get('value', '') + ''.join(map(get_contents, x.get('content'))) + '</blockquote>'
|
||||||
elif otype == 'media':
|
elif otype == 'media':
|
||||||
if x['subType'] == 'photo':
|
if x['subType'] == 'photo':
|
||||||
return '<div><div><img src="{}"></div><div>{}</div></div>'.format(
|
return '<div><div class="img"><img src="{}"></div><div class="cap">{}</div></div>'.format(
|
||||||
x['data']['photo']['src'], x['data']['photo']['caption'])
|
x['data']['photo']['src'], x['data']['photo']['caption'])
|
||||||
elif x['subType'] == 'chart':
|
elif x['subType'] == 'chart':
|
||||||
if x['data'] and x['data']['chart']:
|
if x['data'] and x['data']['chart']:
|
||||||
@ -58,11 +58,11 @@ class Bloomberg(BasicNewsRecipe):
|
|||||||
simultaneous_downloads = 3
|
simultaneous_downloads = 3
|
||||||
|
|
||||||
extra_css = '''
|
extra_css = '''
|
||||||
#bold {font-weight:bold;}
|
.auth {font-size:small; font-weight:bold;}
|
||||||
#auth {font-size:small; font-weight:bold;}
|
.time, .chart {font-size:small;}
|
||||||
#time, .chart {font-size:small;}
|
.subhead {font-style:italic; color:#404040;}
|
||||||
#subhead {font-style:italic; color:#404040;}
|
.cat {font-size:small; color:gray;}
|
||||||
.news-figure-caption-text, #cap, #img {font-size:small; text-align:center;}
|
.news-figure-caption-text, .cap, .img {font-size:small; text-align:center;}
|
||||||
.news-figure-credit {font-size:small; text-align:center; color:#202020;}
|
.news-figure-credit {font-size:small; text-align:center; color:#202020;}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ def get_contents(x):
|
|||||||
return '<blockquote>' + x.get('value', '') + ''.join(map(get_contents, x.get('content'))) + '</blockquote>'
|
return '<blockquote>' + x.get('value', '') + ''.join(map(get_contents, x.get('content'))) + '</blockquote>'
|
||||||
elif otype == 'media':
|
elif otype == 'media':
|
||||||
if x['subType'] == 'photo':
|
if x['subType'] == 'photo':
|
||||||
return '<div><div><img src="{}"></div><div>{}</div></div>'.format(
|
return '<div><div class="img"><img src="{}"></div><div class="cap">{}</div></div>'.format(
|
||||||
x['data']['photo']['src'], x['data']['photo']['caption'])
|
x['data']['photo']['src'], x['data']['photo']['caption'])
|
||||||
elif x['subType'] == 'chart':
|
elif x['subType'] == 'chart':
|
||||||
if x['data'] and x['data']['chart']:
|
if x['data'] and x['data']['chart']:
|
||||||
return '<div><img src="{}"></div>'.format(x['data']['chart']['fallback'])
|
return '<div class="img"><img src="{}"></div>'.format(x['data']['chart']['fallback'])
|
||||||
elif otype == 'link':
|
elif otype == 'link':
|
||||||
if x['data'] and x['content'] and x['content'][0] and x['content'][0]['value']:
|
if x['data'] and x['content'] and x['content'][0] and x['content'][0]['value']:
|
||||||
if 'href' in x['data']:
|
if 'href' in x['data']:
|
||||||
@ -53,7 +53,6 @@ class Bloomberg(BasicNewsRecipe):
|
|||||||
use_embedded_content = False
|
use_embedded_content = False
|
||||||
remove_attributes = ['style', 'height', 'width']
|
remove_attributes = ['style', 'height', 'width']
|
||||||
ignore_duplicate_articles = {'url', 'title'}
|
ignore_duplicate_articles = {'url', 'title'}
|
||||||
resolve_internal_links = True
|
|
||||||
|
|
||||||
# delay = 7 # seconds
|
# delay = 7 # seconds
|
||||||
simultaneous_downloads = 3
|
simultaneous_downloads = 3
|
||||||
|
BIN
recipes/icons/inc42.png
Normal file
BIN
recipes/icons/inc42.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 985 B |
65
recipes/inc42.recipe
Normal file
65
recipes/inc42.recipe
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
|
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
||||||
|
|
||||||
|
class inc42(BasicNewsRecipe):
|
||||||
|
title = 'Inc42'
|
||||||
|
__author__ = 'unkn0wn'
|
||||||
|
description = 'Inc42 is India’s largest tech media platform working with the mission to accelerate the GDP of India’s tech & startup economy.'
|
||||||
|
no_stylesheets = True
|
||||||
|
use_embedded_content = False
|
||||||
|
encoding = 'utf-8'
|
||||||
|
language = 'en_IN'
|
||||||
|
remove_attributes = ['style', 'height', 'width']
|
||||||
|
masthead_url = 'https://omcdn.inc42.com/users/d0ffd8ffa0d2/images/4477fc48bee71659696918-color-black-1-e1576150264134.png?width=224'
|
||||||
|
|
||||||
|
keep_only_tags = [
|
||||||
|
classes('entry-header entry-content'),
|
||||||
|
]
|
||||||
|
|
||||||
|
remove_tags = [
|
||||||
|
dict(name='button'),
|
||||||
|
classes('also-read slick-list slides-three common-card'),
|
||||||
|
]
|
||||||
|
|
||||||
|
ignore_duplicate_articles = {'title'}
|
||||||
|
remove_empty_feeds = True
|
||||||
|
|
||||||
|
articles_are_obfuscated = True
|
||||||
|
|
||||||
|
def get_obfuscated_article(self, url):
|
||||||
|
br = self.get_browser()
|
||||||
|
try:
|
||||||
|
br.open(url)
|
||||||
|
except Exception as e:
|
||||||
|
url = e.hdrs.get('location')
|
||||||
|
soup = self.index_to_soup(url)
|
||||||
|
link = soup.find('a', href=True)
|
||||||
|
skip_sections =[ # add sections you want to skip
|
||||||
|
'/video/', '/videos/', '/media/'
|
||||||
|
]
|
||||||
|
if any(x in link['href'] for x in skip_sections):
|
||||||
|
self.log('Aborting Article ', link['href'])
|
||||||
|
self.abort_article('skipping video links')
|
||||||
|
|
||||||
|
self.log('Downloading ', link['href'])
|
||||||
|
html = br.open(link['href']).read()
|
||||||
|
pt = PersistentTemporaryFile('.html')
|
||||||
|
pt.write(html)
|
||||||
|
pt.close()
|
||||||
|
return pt.name
|
||||||
|
|
||||||
|
feeds = []
|
||||||
|
|
||||||
|
sections = [
|
||||||
|
'features', 'buzz', 'startups', 'resources'
|
||||||
|
]
|
||||||
|
|
||||||
|
for sec in sections:
|
||||||
|
a = 'https://news.google.com/rss/search?q=when:27h+allinurl:inc42.com{}&hl=en-IN&gl=IN&ceid=IN:en'
|
||||||
|
feeds.append((sec.capitalize(), a.format('%2F' + sec + '%2F')))
|
||||||
|
feeds.append(('Others', a.format('')))
|
||||||
|
|
||||||
|
def preprocess_html(self, soup):
|
||||||
|
for img in soup.findAll('img', attrs={'data-src':True}):
|
||||||
|
img['src'] = img['data-src']
|
||||||
|
return soup
|
Loading…
x
Reference in New Issue
Block a user