mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Discover Magazine
This commit is contained in:
parent
cf8fcfe82b
commit
cb14e8f549
@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
discovermagazine.com
|
discovermagazine.com
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import re
|
import re, mechanize, json, cookielib
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
|
||||||
class DiscoverMagazine(BasicNewsRecipe):
|
class DiscoverMagazine(BasicNewsRecipe):
|
||||||
@ -35,19 +35,43 @@ class DiscoverMagazine(BasicNewsRecipe):
|
|||||||
|
|
||||||
# Login stuff
|
# Login stuff
|
||||||
needs_subscription = True
|
needs_subscription = True
|
||||||
use_javascript_to_login = True
|
|
||||||
requires_version = (0, 9, 20)
|
|
||||||
|
|
||||||
def javascript_login(self, br, username, password):
|
def get_browser(self):
|
||||||
br.visit('http://discovermagazine.com', timeout=120)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
f = br.select_form('div.login.section div.form')
|
rq = mechanize.Request(
|
||||||
f['username'] = username
|
'https://secure.kalmbach.com/kserv/api/authentication/login', headers={
|
||||||
f['password'] = password
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
br.submit('input[id="signInButton"]', timeout=120)
|
'Referer': 'http://discovermagazine.com',
|
||||||
br.run_for_a_time(20)
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||||
|
'Accept-Language': 'en-US,en;q=0.5',
|
||||||
|
'Origin': 'http://discovermagazine.com',
|
||||||
|
}, data=json.dumps(
|
||||||
|
{'appId': '2', 'email':self.username, 'password':self.password}))
|
||||||
|
br.set_debug_http(True)
|
||||||
|
br.open(rq)
|
||||||
|
data = json.loads(br.open(rq).read())
|
||||||
|
if not data.get('success'):
|
||||||
|
raise ValueError('Failed to login')
|
||||||
|
session_id = data['sessionId']
|
||||||
|
if hasattr(br, 'set_cookie'):
|
||||||
|
br.set_cookie('KSERV', session_id, 'discovermagazine.com')
|
||||||
|
else:
|
||||||
|
c = cookielib.Cookie(
|
||||||
|
None, 'KSERV', session_id,
|
||||||
|
None, False,
|
||||||
|
'discovermagazine.com', True, False,
|
||||||
|
'/', True,
|
||||||
|
False, None, False, None, None, None)
|
||||||
|
br.cookiejar.set_cookie(c)
|
||||||
|
res = br.open('http://discovermagazine.com')
|
||||||
|
br.set_debug_http(False)
|
||||||
|
raw = res.read()
|
||||||
|
if '>Logout<' not in raw:
|
||||||
|
raise ValueError('Failed to login')
|
||||||
|
return br
|
||||||
|
|
||||||
# End login stuff
|
# End login stuff
|
||||||
|
|
||||||
|
|
||||||
def append_page(self, soup, appendtag, position):
|
def append_page(self, soup, appendtag, position):
|
||||||
pager = soup.find('span',attrs={'class':'next'})
|
pager = soup.find('span',attrs={'class':'next'})
|
||||||
if pager:
|
if pager:
|
||||||
|
@ -7,39 +7,64 @@ __copyright__ = '2015 Michael Marotta <mikefm at gmail.net>'
|
|||||||
'''
|
'''
|
||||||
discovermagazine.com
|
discovermagazine.com
|
||||||
'''
|
'''
|
||||||
import re
|
import re, json, cookielib
|
||||||
|
import mechanize
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
|
||||||
class DiscoverMagazine(BasicNewsRecipe):
|
class DiscoverMagazine(BasicNewsRecipe):
|
||||||
|
|
||||||
title = 'Discover Magazine Monthly'
|
title = 'Discover Magazine Monthly'
|
||||||
__author__ = 'Michael Marotta'
|
__author__ = 'Kovid Goyal'
|
||||||
description = 'Monthly magazine version of Discover Magazine (not rss feed).'
|
description = 'Monthly magazine version of Discover Magazine (not rss feed).'
|
||||||
language = 'en'
|
language = 'en'
|
||||||
encoding = 'utf-8'
|
encoding = 'utf-8'
|
||||||
simultaneous_downloads = 20
|
simultaneous_downloads = 20
|
||||||
tags = 'news, technology, science'
|
tags = 'news, technology, science'
|
||||||
INDEX = 'http://www.discovermagazine.com'
|
INDEX = 'http://discovermagazine.com'
|
||||||
|
|
||||||
keep_only_tags = [
|
keep_only_tags = [
|
||||||
{'attrs':{'class':['headline', 'deck', 'belowDeck', 'mediaContainer', 'segment', 'cover']}},
|
{'attrs':{'class':['headline', 'deck', 'belowDeck', 'mediaContainer', 'segment', 'cover']}},
|
||||||
]
|
]
|
||||||
remove_tags = [dict(name='div', attrs={'class': ['ladder', 'mobile', 'popular', 'open', 'scistarter']})]
|
remove_tags = [dict(name='div', attrs={'class': ['ladder', 'mobile', 'popular', 'open', 'scistarter']})]
|
||||||
|
|
||||||
# Login stuff
|
# Login {{{
|
||||||
needs_subscription = True
|
needs_subscription = True
|
||||||
use_javascript_to_login = True
|
|
||||||
requires_version = (0, 9, 20)
|
|
||||||
|
|
||||||
def javascript_login(self, br, username, password):
|
def get_browser(self):
|
||||||
br.visit('http://discovermagazine.com', timeout=120)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
f = br.select_form('div.login.section div.form')
|
rq = mechanize.Request(
|
||||||
f['username'] = username
|
'https://secure.kalmbach.com/kserv/api/authentication/login', headers={
|
||||||
f['password'] = password
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
br.submit('input[id="signInButton"]', timeout=120)
|
'Referer': 'http://discovermagazine.com',
|
||||||
br.run_for_a_time(20)
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||||
# br.show_browser()
|
'Accept-Language': 'en-US,en;q=0.5',
|
||||||
# End login stuff
|
'Origin': 'http://discovermagazine.com',
|
||||||
|
}, data=json.dumps(
|
||||||
|
{'appId': '2', 'email':self.username, 'password':self.password}))
|
||||||
|
br.set_debug_http(True)
|
||||||
|
br.open(rq)
|
||||||
|
data = json.loads(br.open(rq).read())
|
||||||
|
if not data.get('success'):
|
||||||
|
raise ValueError('Failed to login')
|
||||||
|
session_id = data['sessionId']
|
||||||
|
if hasattr(br, 'set_cookie'):
|
||||||
|
br.set_cookie('KSERV', session_id, 'discovermagazine.com')
|
||||||
|
else:
|
||||||
|
c = cookielib.Cookie(
|
||||||
|
None, 'KSERV', session_id,
|
||||||
|
None, False,
|
||||||
|
'discovermagazine.com', True, False,
|
||||||
|
'/', True,
|
||||||
|
False, None, False, None, None, None)
|
||||||
|
br.cookiejar.set_cookie(c)
|
||||||
|
res = br.open('http://discovermagazine.com')
|
||||||
|
br.set_debug_http(False)
|
||||||
|
raw = res.read()
|
||||||
|
if '>Logout<' not in raw:
|
||||||
|
raise ValueError('Failed to login')
|
||||||
|
return br
|
||||||
|
|
||||||
|
# End login }}}
|
||||||
|
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
preprocess_regexps = [(re.compile(r'<br[ ]*/>', re.IGNORECASE), lambda m: ''),
|
preprocess_regexps = [(re.compile(r'<br[ ]*/>', re.IGNORECASE), lambda m: ''),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user