| 1 |
from calibre.web.feeds.news import BasicNewsRecipe, LoginFailed |
| 2 |
|
| 3 |
|
| 4 |
class SCPrintMagazine(BasicNewsRecipe): |
| 5 |
title = 'SC Print Magazine' |
| 6 |
__author__ = 'Tony Maro' |
| 7 |
description = 'Last print version of the data security magazine' |
| 8 |
INDEX = 'http://www.scmagazineus.com/issuearchive/' |
| 9 |
no_stylesheets = True |
| 10 |
language = 'en' |
| 11 |
keep_only_tags = [dict(id=['article', 'review'])] |
| 12 |
remove_tags = [dict(id=['articlePrintTools', 'reviewBodyColumn'])] |
| 13 |
LOG_IN = 'http://www.scmagazineus.com/login/' |
| 14 |
tags = 'News,SC Magazine' |
| 15 |
needs_subscription = True |
| 16 |
|
| 17 |
def parse_index(self): |
| 18 |
articles = [] |
| 19 |
issuelink = printsections = None |
| 20 |
|
| 21 |
soup = self.index_to_soup(self.INDEX) |
| 22 |
sectit = soup.find('div', attrs={'class': 'issueArchiveItem'}) |
| 23 |
if sectit is not None: |
| 24 |
linkt = sectit.find('a') |
| 25 |
issuelink = linkt['href'] |
| 26 |
imgt = sectit.find('img') |
| 27 |
self.cover_url = imgt['src'] |
| 28 |
|
| 29 |
if issuelink is not None: |
| 30 |
issue = self.index_to_soup(issuelink) |
| 31 |
if issue is not None: |
| 32 |
printsections = issue.findAll('div', attrs={'class': 'PrintSection'}) |
| 33 |
if printsections is not None: |
| 34 |
for printsection in printsections: |
| 35 |
onesection = [] |
| 36 |
sectiontitle = printsection.find('h3').contents[0] |
| 37 |
articlesec = printsection.findAll('div', attrs={'class': 'IssueArchiveFormat'}) |
| 38 |
if articlesec is not None: |
| 39 |
''' got articles ''' |
| 40 |
for onearticle in articlesec: |
| 41 |
''' process one article ''' |
| 42 |
arttitlet = onearticle.find('h3') |
| 43 |
if arttitlet is not None: |
| 44 |
mylink = arttitlet.find('a') |
| 45 |
if mylink is not None: |
| 46 |
if mylink.get('title'): |
| 47 |
arttitle = mylink['title'] |
| 48 |
else: |
| 49 |
arttitle = 'unknown' |
| 50 |
if mylink.get('href'): |
| 51 |
artlink = mylink['href'] |
| 52 |
artlink = artlink.replace('/article', '/printarticle') |
| 53 |
artlink = artlink.replace('/review', '/printreview') |
| 54 |
deck = onearticle.find('div', attrs={'class': 'deck'}) |
| 55 |
if deck is not None: |
| 56 |
deck = deck.contents[0] |
| 57 |
onesection.append({'title': arttitle, 'url': artlink, 'description': deck, 'date': ''}) |
| 58 |
articles.append((sectiontitle, onesection)) |
| 59 |
|
| 60 |
return articles |
| 61 |
|
| 62 |
def get_browser(self): |
| 63 |
br = BasicNewsRecipe.get_browser(self) |
| 64 |
br.open(self.LOG_IN) |
| 65 |
br.select_form(name='aspnetForm') |
| 66 |
br['ctl00$ctl00$cphAllPageContent$cphMainContent$SubscriberEasyLoginView1$txtEmail'] = self.username |
| 67 |
br['ctl00$ctl00$cphAllPageContent$cphMainContent$SubscriberEasyLoginView1$txtPassword'] = self.password |
| 68 |
raw = br.submit('ctl00$ctl00$cphAllPageContent$cphMainContent$SubscriberEasyLoginView1$btnLogin').read() |
| 69 |
if 'Logout</a>' not in raw: |
| 70 |
raise LoginFailed(_('Failed to log in, check your username and password for the calibre Periodicals service.')) |
| 71 |
return br |