[nijie] cache login sessions
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2015 Mike Fährmann
|
# Copyright 2015, 2016 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
from .common import AsynchronousExtractor, Message
|
from .common import AsynchronousExtractor, Message
|
||||||
from .. import config, text
|
from .. import config, text
|
||||||
|
from ..cache import cache
|
||||||
|
|
||||||
class NijieUserExtractor(AsynchronousExtractor):
|
class NijieUserExtractor(AsynchronousExtractor):
|
||||||
"""Extract all works of a single nijie-user"""
|
"""Extract all works of a single nijie-user"""
|
||||||
@@ -33,7 +34,10 @@ class NijieUserExtractor(AsynchronousExtractor):
|
|||||||
self.session.headers["Referer"] = self.artist_url
|
self.session.headers["Referer"] = self.artist_url
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
self.login()
|
self.session.cookies = self.login(
|
||||||
|
config.interpolate(("extractor", self.category, "email")),
|
||||||
|
config.interpolate(("extractor", self.category, "password"))
|
||||||
|
)
|
||||||
data = self.get_job_metadata()
|
data = self.get_job_metadata()
|
||||||
yield Message.Version, 1
|
yield Message.Version, 1
|
||||||
yield Message.Directory, data
|
yield Message.Directory, data
|
||||||
@@ -65,12 +69,11 @@ class NijieUserExtractor(AsynchronousExtractor):
|
|||||||
"image-id": image_id,
|
"image-id": image_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
def login(self):
|
@cache(maxage=30*24*60*60, keyarg=1)
|
||||||
|
def login(self, email, password):
|
||||||
"""Login and obtain session cookie"""
|
"""Login and obtain session cookie"""
|
||||||
params = {
|
params = {"email": email, "password": password}
|
||||||
"email": config.get(("extractor", self.category, "email")),
|
|
||||||
"password": config.get(("extractor", self.category, "password")),
|
|
||||||
}
|
|
||||||
page = self.session.post("https://nijie.info/login_int.php", data=params).text
|
page = self.session.post("https://nijie.info/login_int.php", data=params).text
|
||||||
if "//nijie.info/login.php" in page:
|
if "//nijie.info/login.php" in page:
|
||||||
raise Exception("login failed")
|
raise Exception("login failed")
|
||||||
|
return self.session.cookies
|
||||||
|
|||||||
Reference in New Issue
Block a user