Created
September 29, 2013 21:02
-
-
Save simonbowen/6756511 to your computer and use it in GitHub Desktop.
SleekXMPP and gevent
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
import sleekxmpp | |
import gevent | |
import sqlite3 | |
class Message(sleekxmpp.ClientXMPP): | |
def __init__(self, jid, password): | |
super(Message, self).__init__(jid, password) | |
self.add_event_handler('session_start', self.start) | |
self.add_event_handler('message', self.message) | |
def start(self, event): | |
self.send_presence() | |
self.get_roster() | |
def message(self, msg): | |
print msg['body'] | |
conn = sqlite3.connect('xmpp.db') | |
c = conn.cursor() | |
c.execute("INSERT INTO messages(message) VALUES ('%s');" % msg['body']); | |
conn.commit() | |
conn.close() | |
def boot(jid, password): | |
xmpp = Message(jid, password) | |
xmpp.register_plugin('xep_0030') | |
xmpp.register_plugin('xep_0199') | |
if xmpp.connect(): | |
xmpp.process(block=False) | |
else: | |
print("Something went wrong") | |
if __name__ == '__main__': | |
threads = [] | |
threads.append(gevent.spawn(boot, 'simon@simons-macbook-pro.local', '*********')) | |
threads.append(gevent.spawn(boot, 'georgina@simons-macbook-pro.local', '*********')) | |
gevent.joinall(threads) | |
print "XMPP Accounts Booted" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment