| 1 |
#!/usr/bin/env python |
| 2 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 3 |
|
| 4 |
|
| 5 |
def absurl(url): |
| 6 |
if url.startswith('/'): |
| 7 |
return 'https://www.livelaw.in' + url |
| 8 |
|
| 9 |
|
| 10 |
class livelaw(BasicNewsRecipe): |
| 11 |
title = 'Live Law' |
| 12 |
__author__ = 'unkn0wn' |
| 13 |
description = 'Live Law is a comprehensive legal news portal which is committed to providing accurate and honest news about legal developments.' |
| 14 |
no_stylesheets = True |
| 15 |
use_embedded_content = False |
| 16 |
encoding = 'utf-8' |
| 17 |
language = 'en_IN' |
| 18 |
remove_attributes = ['height', 'width', 'style'] |
| 19 |
masthead_url = 'https://www.livelaw.in/images/logo.png' |
| 20 |
remove_empty_feeds = True |
| 21 |
remove_javascript = True |
| 22 |
ignore_duplicate_articles = {'title', 'url'} |
| 23 |
simultaneous_downloads = 1 |
| 24 |
|
| 25 |
extra_css = ''' |
| 26 |
.news_detail_person_detail {font-size:small; color:#202020;} |
| 27 |
.news-description { color:#202020; font-style:italic; } |
| 28 |
''' |
| 29 |
|
| 30 |
keep_only_tags = [dict(name='div', attrs={'id': 'page-content-wrapper'})] |
| 31 |
|
| 32 |
remove_tags = [ |
| 33 |
classes('in-image-ad-wrap news_details_social_media_icons news_details_social_icon_desktop audioSection news_details_tags_row nextpage'), |
| 34 |
dict(attrs={'class': lambda x: x and 'inside-post-ad' in x}), |
| 35 |
dict(attrs={'id': ['news_buzz_updates', 'after_tags', 'comments_before', 'comments', 'comments_after']}), |
| 36 |
] |
| 37 |
|
| 38 |
def preprocess_html(self, soup): |
| 39 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 40 |
img['src'] = img['data-src'] |
| 41 |
for h2 in soup.findAll(['h2', 'h6']): |
| 42 |
h2.name = 'p' |
| 43 |
return soup |
| 44 |
|
| 45 |
def parse_index(self): |
| 46 |
index = 'https://www.livelaw.in/' |
| 47 |
sections = ['top-stories', 'supreme-court', 'high-court', 'news-updates', 'consumer-cases', 'articles', 'lawschool', 'law-firms', 'round-ups'] |
| 48 |
feeds = [] |
| 49 |
soup = self.index_to_soup(index) |
| 50 |
for sec in sections: |
| 51 |
section = sec.capitalize() |
| 52 |
self.log(section) |
| 53 |
articles = [] |
| 54 |
for a in soup.findAll('a', attrs={'href': lambda x: x and x.startswith('/' + sec + '/')}): |
| 55 |
url = absurl(a['href'].split('?')[0]) |
| 56 |
if url in {index + sec + '/', index + sec}: |
| 57 |
continue |
| 58 |
if not url[-1].isdigit(): |
| 59 |
continue |
| 60 |
title = self.tag_to_string(a) |
| 61 |
self.log('\t', title, '\n\t\t', url) |
| 62 |
articles.append({'title': title, 'url': url}) |
| 63 |
if articles: |
| 64 |
feeds.append((section, articles)) |
| 65 |
return feeds |