| 1 |
__license__ = 'GPL v3' |
| 2 |
__copyright__ = '2022, Howard Cornett howard at myreadinglife.com>' |
| 3 |
''' |
| 4 |
https://skepticalinquirer.org/ |
| 5 |
''' |
| 6 |
|
| 7 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 8 |
|
| 9 |
|
| 10 |
def classes(classes): |
| 11 |
q = frozenset(classes.split(' ')) |
| 12 |
return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)}) |
| 13 |
|
| 14 |
|
| 15 |
class FreeInquiry(BasicNewsRecipe): |
| 16 |
title = 'The Skeptical Inquirer' |
| 17 |
__author__ = 'Howard Cornett' |
| 18 |
description = 'The Magazine for Science and Reason' |
| 19 |
publisher = 'Center for Inquiry' |
| 20 |
no_stylesheets = True |
| 21 |
encoding = 'utf-8' |
| 22 |
use_embedded_content = False |
| 23 |
language = 'en' |
| 24 |
ignore_duplicate_articles = {'url'} |
| 25 |
remove_empty_feeds = True |
| 26 |
needs_subscription = True |
| 27 |
extra_css = ''' |
| 28 |
.entry-header{ |
| 29 |
text-transform: uppercase; |
| 30 |
vertical-align: baseline; |
| 31 |
display: inline; |
| 32 |
} |
| 33 |
ul li{display: inline} |
| 34 |
''' |
| 35 |
|
| 36 |
remove_tags = [ |
| 37 |
classes('main-navigation swp-social-panel see-more user-admin d-print-none post-18669 wc-memberships-message'), |
| 38 |
dict(id=['sidebar-TOC', 'loginModal']), |
| 39 |
] |
| 40 |
|
| 41 |
def get_browser(self): |
| 42 |
br = BasicNewsRecipe.get_browser(self) |
| 43 |
if self.username is not None and self.password is not None: |
| 44 |
br.open('https://skepticalinquirer.org/member-login/') |
| 45 |
br.select_form(name='loginform') |
| 46 |
br['log'] = self.username |
| 47 |
br['pwd'] = self.password |
| 48 |
br.submit() |
| 49 |
return br |
| 50 |
|
| 51 |
def parse_free_inquiry_index_page(self, currenturl, seen): |
| 52 |
self.log('Parsing index page', currenturl) |
| 53 |
soup = self.index_to_soup(currenturl) |
| 54 |
cover = soup.find('img', class_='attachment-medium') |
| 55 |
cover_img_split = cover['data-srcset'].split(',')[2] |
| 56 |
cover_img = cover_img_split.split()[0] |
| 57 |
if cover is not None: |
| 58 |
self.cover_url = cover_img |
| 59 |
for row in soup.findAll('div', attrs={'class': 'article-row'}): |
| 60 |
for info in row.findAll('div', attrs={'class': 'article-info'}): |
| 61 |
p = info.find('p') |
| 62 |
desc = p.text |
| 63 |
for span in info.findAll('span'): |
| 64 |
if span.find('h5') is not None: |
| 65 |
for h5 in span.find('h5'): |
| 66 |
if h5 is not None: |
| 67 |
art_title = h5 |
| 68 |
else: |
| 69 |
art_title = '' |
| 70 |
if span.a['href'] is not None: |
| 71 |
url = span.a['href'] |
| 72 |
else: |
| 73 |
url = '' |
| 74 |
seen.add(url) |
| 75 |
self.log('Found article:', art_title) |
| 76 |
yield {'title': art_title, 'url': url, 'description': desc} |
| 77 |
|
| 78 |
def parse_index(self): |
| 79 |
baseurl = 'https://skepticalinquirer.org/latest/' |
| 80 |
articles = [] |
| 81 |
seen = set() |
| 82 |
articles.extend(self.parse_free_inquiry_index_page(baseurl, seen)) |
| 83 |
|
| 84 |
return [('Magazine Articles', articles)] |