| 1 |
#!/usr/bin/env python |
| 2 |
from calibre.web.feeds.news import BasicNewsRecipe, prefixed_classes |
| 3 |
|
| 4 |
|
| 5 |
class bar(BasicNewsRecipe): |
| 6 |
title = 'Bar and Bench' |
| 7 |
__author__ = 'unkn0wn' |
| 8 |
description = ( |
| 9 |
'Bar & Bench is the premier online portal for Indian legal news. News, interviews,' |
| 10 |
' and columns related to the Supreme Court of India and the High Courts are published.' |
| 11 |
) |
| 12 |
language = 'en_IN' |
| 13 |
masthead_url = 'https://gumlet.assettype.com/barandbench/2019-12/7a743b15-5d5d-44d7-96c2-13616780ed95/brand_2x.png' |
| 14 |
|
| 15 |
no_stylesheets = True |
| 16 |
remove_javascript = True |
| 17 |
remove_attributes = ['height', 'width', 'style'] |
| 18 |
|
| 19 |
keep_only_tags = [prefixed_classes('text-story-m_header-details__ text-story-m_hero-image__ text-story-m_story-content-inner-wrapper__')] |
| 20 |
|
| 21 |
remove_tags = [prefixed_classes('text-story-m_story-tags__ story-footer-module__metype__'), dict(name='svg')] |
| 22 |
|
| 23 |
def preprocess_html(self, soup): |
| 24 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 25 |
img['src'] = img['data-src'] |
| 26 |
return soup |
| 27 |
|
| 28 |
ignore_duplicate_articles = {'title'} |
| 29 |
resolve_internal_links = True |
| 30 |
remove_empty_feeds = True |
| 31 |
|
| 32 |
def parse_index(self): |
| 33 |
index = 'https://www.barandbench.com/' |
| 34 |
sections = ['news', 'columns', 'interviews', 'law-firms', 'apprentice-lawyer', 'legal-jobs'] |
| 35 |
feeds = [] |
| 36 |
soup = self.index_to_soup(index) |
| 37 |
for sec in sections: |
| 38 |
section = sec.capitalize() |
| 39 |
self.log(section) |
| 40 |
articles = [] |
| 41 |
for a in soup.findAll('a', attrs={'href': lambda x: x and x.startswith(index + sec + '/')}): |
| 42 |
url = a['href'].split('?')[0] |
| 43 |
if url in {index + sec + '/', index + sec}: |
| 44 |
continue |
| 45 |
title = self.tag_to_string(a) |
| 46 |
self.log('\t', title, '\n\t\t', url) |
| 47 |
articles.append({'title': title, 'url': url}) |
| 48 |
if articles: |
| 49 |
feeds.append((section, articles)) |
| 50 |
return feeds |