mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Initial shelve support for persistance in sessions.
This commit is contained in:
parent
e7943cba50
commit
594985dec4
@ -12,6 +12,7 @@ import logging
|
||||
from twitter import utils
|
||||
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
|
||||
import config_utils
|
||||
import shelve
|
||||
from mysc.thread_utils import stream_threaded
|
||||
from pubsub import pub
|
||||
log = logging.getLogger("sessionmanager.session")
|
||||
@ -92,6 +93,7 @@ class Session(object):
|
||||
self.settings = None
|
||||
self.twitter = twitter.twitter.twitter()
|
||||
self.db={}
|
||||
self.deshelve()
|
||||
self.reconnection_function_active = False
|
||||
self.counter = 0
|
||||
self.lists = []
|
||||
@ -356,3 +358,20 @@ class Session(object):
|
||||
else:
|
||||
self.main_stream.disconnect()
|
||||
del self.main_stream
|
||||
|
||||
def shelve(self):
|
||||
"Shelve the database to allow for persistance."
|
||||
shelfname=paths.config_path(str(self.session_id)+".db")
|
||||
shelf=shelve.open(paths.config_path(shelfname),'c')
|
||||
for key,value in self.db.items():
|
||||
shelf[key]=value
|
||||
shelf.close()
|
||||
|
||||
def deshelve(self):
|
||||
"Import a shelved database."
|
||||
shelfname=paths.config_path(str(self.session_id)+".db")
|
||||
shelf=shelve.open(paths.config_path(shelfname),'c')
|
||||
for key,value in shelf.items():
|
||||
self.db[key]=value
|
||||
shelf.close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user