| 1 |
#!/usr/bin/env python |
| 2 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 3 |
|
| 4 |
|
| 5 |
class inc42(BasicNewsRecipe): |
| 6 |
title = 'Inc42' |
| 7 |
__author__ = 'unkn0wn' |
| 8 |
description = 'Inc42 is India’s largest tech media platform working with the mission to accelerate the GDP of India’s tech & startup economy.' |
| 9 |
no_stylesheets = True |
| 10 |
use_embedded_content = False |
| 11 |
encoding = 'utf-8' |
| 12 |
language = 'en_IN' |
| 13 |
remove_attributes = ['style', 'height', 'width'] |
| 14 |
masthead_url = 'https://omcdn.inc42.com/users/d0ffd8ffa0d2/images/4477fc48bee71659696918-color-black-1-e1576150264134.png?width=224' |
| 15 |
|
| 16 |
keep_only_tags = [ |
| 17 |
classes('entry-header entry-content'), |
| 18 |
] |
| 19 |
|
| 20 |
remove_tags = [ |
| 21 |
dict(name='button'), |
| 22 |
classes('also-read slick-list slides-three common-card'), |
| 23 |
] |
| 24 |
|
| 25 |
ignore_duplicate_articles = {'title', 'url'} |
| 26 |
remove_empty_feeds = True |
| 27 |
|
| 28 |
def parse_index(self): |
| 29 |
index = 'https://inc42.com/' |
| 30 |
sections = ['features', 'buzz', 'startups', 'resources'] |
| 31 |
feeds = [] |
| 32 |
soup = self.index_to_soup(index) |
| 33 |
for sec in sections: |
| 34 |
section = sec.capitalize() |
| 35 |
self.log(section) |
| 36 |
articles = [] |
| 37 |
for a in soup.findAll('a', attrs={'href': lambda x: x and x.startswith(index + sec + '/')}): |
| 38 |
url = a['href'] |
| 39 |
if url == index + sec + '/': |
| 40 |
continue |
| 41 |
title = self.tag_to_string(a) |
| 42 |
self.log('\t', title, '\n\t\t', url) |
| 43 |
articles.append({'title': title, 'url': url}) |
| 44 |
if articles: |
| 45 |
feeds.append((section, articles)) |
| 46 |
return feeds |
| 47 |
|
| 48 |
def preprocess_html(self, soup): |
| 49 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 50 |
img['src'] = img['data-src'] |
| 51 |
return soup |