plugin CS: use of PersistentBinaryData to store profile's information, and clean up on profile disconnection.
/!\ The plugin doesn't work anymore, probably due to some change on CS website.
This commit is contained in:
parent
04e8ab3291
commit
672e69593b
1 changed files with 14 additions and 7 deletions
|
|
@ -26,6 +26,7 @@ from twisted.words.protocols.jabber import client, jid, xmlstream
|
|||
from twisted.words.protocols.jabber import error as jab_error
|
||||
from twisted.words.protocols.jabber.xmlstream import IQ
|
||||
from twisted.web.client import getPage
|
||||
from sat.memory.persistent import PersistentBinaryDict
|
||||
import os.path
|
||||
import pdb
|
||||
|
||||
|
|
@ -73,10 +74,21 @@ class CS_Plugin():
|
|||
host.memory.importParams(CS_Plugin.params)
|
||||
#menu
|
||||
host.importMenu(_("Plugin"), "CouchSurfing", self.menuSelected, help_string = _("Launch CoushSurfing management interface"))
|
||||
self.data=self.host.memory.getPrivate('plugin_cs_data') or {} #TODO: delete cookies/data after a while
|
||||
self.data={} #TODO: delete cookies/data after a while
|
||||
self.host.registerGeneralCB("plugin_CS_sendMessage", self.sendMessage)
|
||||
self.host.registerGeneralCB("plugin_CS_showUnreadMessages", self.showUnreadMessages)
|
||||
|
||||
def profileConnected(self, profile):
|
||||
self.data[profile] = PersistentBinaryDict("plugin_CS", profile)
|
||||
def dataLoaded(ignore):
|
||||
if not self.data[profile]:
|
||||
self.data[profile] = {'cookies':{}}
|
||||
|
||||
self.data[profile].load().addCallback(dataLoaded)
|
||||
|
||||
def profileDisconnected(self, profile):
|
||||
del self.data[profile]
|
||||
|
||||
def erroCB(self, e, id):
|
||||
"""Called when something is going wrong when contacting CS website"""
|
||||
#pdb.set_trace()
|
||||
|
|
@ -94,10 +106,7 @@ class CS_Plugin():
|
|||
|
||||
post_data = urllib.urlencode({'auth_login[un]':login,'auth_login[pw]':password,'auth_login[action]':'Login...'})
|
||||
|
||||
if not self.data.has_key(profile):
|
||||
self.data[profile] = {'cookies':{}}
|
||||
else:
|
||||
self.data[profile]['cookies'] = {}
|
||||
self.data[profile]['cookies'] = {}
|
||||
|
||||
d = getPage('http://www.couchsurfing.org/login.html', method='POST', postdata=post_data, headers={'Content-Type':'application/x-www-form-urlencoded'} , agent=AGENT, cookies=self.data[profile]['cookies'])
|
||||
d.addCallback(self.__connectionCB, id, profile)
|
||||
|
|
@ -194,8 +203,6 @@ class CS_Plugin():
|
|||
else:
|
||||
#no, we show the result
|
||||
self.host.bridge.actionResult("XMLUI", id, {"type":"window", "xml":self.__buildUI(self.data[profile])})
|
||||
#and save the data
|
||||
self.host.memory.setPrivate('plugin_cs_data', self.data)
|
||||
|
||||
def __sendMessage(self, answer, subject, message, data, recipient_list, id, profile):
|
||||
"""Send actually the message
|
||||
|
|
|
|||
Loading…
Reference in a new issue