mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Caravan Magazine
Add support for optional login
This commit is contained in:
parent
ccf23b7b86
commit
8b7b02cc41
@ -1,4 +1,11 @@
|
|||||||
# coding: utf-8
|
#!/usr/bin/env python2
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from mechanize import Request
|
||||||
|
|
||||||
from calibre.web.feeds.recipes import BasicNewsRecipe
|
from calibre.web.feeds.recipes import BasicNewsRecipe
|
||||||
|
|
||||||
|
|
||||||
@ -16,6 +23,7 @@ class CaravanMagazine(BasicNewsRecipe):
|
|||||||
language = 'en_IN'
|
language = 'en_IN'
|
||||||
timefmt = ' [%b, %Y]'
|
timefmt = ' [%b, %Y]'
|
||||||
encoding = 'utf-8'
|
encoding = 'utf-8'
|
||||||
|
needs_subscription = 'optional'
|
||||||
|
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
|
|
||||||
@ -29,6 +37,32 @@ class CaravanMagazine(BasicNewsRecipe):
|
|||||||
dict(attrs={'class': ['share-with']}),
|
dict(attrs={'class': ['share-with']}),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_browser(self, *args, **kw):
|
||||||
|
br = BasicNewsRecipe.get_browser(self, *args, **kw)
|
||||||
|
if not self.username or not self.password:
|
||||||
|
return br
|
||||||
|
data = json.dumps({'email': self.username, 'name': '', 'password': self.password})
|
||||||
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
|
rq = Request(
|
||||||
|
url='https://caravanmagazine.in/api/users/login',
|
||||||
|
data=data,
|
||||||
|
headers={
|
||||||
|
'Accept': 'application/json, text/plain, */*',
|
||||||
|
'Origin': 'https://caravanmagazine.in',
|
||||||
|
'Referer': 'https://caravanmagazine.in/',
|
||||||
|
'Content-type': 'application/json;charset=UTF-8',
|
||||||
|
},
|
||||||
|
method='POST'
|
||||||
|
)
|
||||||
|
res = br.open(rq).read()
|
||||||
|
res = res.decode('utf-8')
|
||||||
|
self.log('Login request response: {}'.format(res))
|
||||||
|
res = json.loads(res)
|
||||||
|
if res['code'] != 200 or res['message'] != "Login success":
|
||||||
|
raise ValueError('Login failed, check your username and password')
|
||||||
|
return br
|
||||||
|
|
||||||
# To parse artice toc
|
# To parse artice toc
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
base_url = 'https://www.caravanmagazine.in/'
|
base_url = 'https://www.caravanmagazine.in/'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user