forked from alephdata/memorious
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
store http sessions in redis separately
- Loading branch information
Showing
9 changed files
with
59 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ data* | |
memorious.env | ||
docker-compose.* | ||
.git | ||
.tox | ||
.gitignore | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import random | ||
|
||
|
||
class UserAgent(object): | ||
|
||
def __init__(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pickle | ||
import codecs | ||
import logging | ||
from hashlib import sha1 | ||
|
||
from memorious.model.common import Base | ||
from memorious.util import make_key | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class SessionState(Base): | ||
"""An HTTP session state.""" | ||
|
||
@classmethod | ||
def save(cls, crawler, session): | ||
session = pickle.dumps(session) | ||
session = codecs.encode(session, 'base64') | ||
key = sha1(session).hexdigest()[:15] | ||
key = make_key(crawler, "session", key) | ||
cls.conn.set(key, session, ex=84600) | ||
return key | ||
|
||
@classmethod | ||
def get(cls, crawler, key): | ||
value = cls.conn.get(make_key(crawler, "session", key)) | ||
if value is not None: | ||
session = codecs.decode(bytes(value, 'utf-8'), 'base64') | ||
return pickle.loads(session) | ||
|
||
@classmethod | ||
def delete(cls, crawler): | ||
for key in cls.conn.scan_iter(make_key(crawler, "session", "*")): | ||
cls.conn.delete(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters