I'd suggest you to use sleekxmpp. You can register a callback like this:
self.add_event_handler("changed_status", self.my_callback_function)
Where self is your instance of a class that inherits from sleekxmpp.ClientXMPP
.
Edit: I've just made this code for you (free to use as you wish)
import sleekxmpp
from ConfigParser import ConfigParser
class StatusWatcher(sleekxmpp.ClientXMPP):
def __init__(self, jid_to_watch):
self._jid_to_watch = jid_to_watch
config = ConfigParser()
config.read("config.ini")
jid = config.get("general", "jid")
resource = config.get("general", "resource")
password = config.get("general", "password")
sleekxmpp.ClientXMPP.__init__(self, jid + "/" + resource, password)
self.add_event_handler("session_start", self.handle_XMPP_connected)
self.add_event_handler("changed_status", self.handle_changed_status)
def handle_XMPP_connected(self, event):
print "connected"
self.sendPresence(pstatus="I'm just a Bot.")
self.get_roster()
def handle_changed_status(self, pres):
if pres['from'].bare == self._jid_to_watch:
print pres['status']
xmpp = StatusWatcher("[email protected]") # The account to monitor
xmpp.register_plugin('xep_0030')
xmpp.register_plugin('xep_0199')
if xmpp.connect():
xmpp.process(threaded=False)
You need to create a file config.ini
with your credentials:
[general]
[email protected]
resource=presence_watcher
password=yourpwd