2010-07-23 23:41:11 +00:00
|
|
|
#!/usr/bin/env python
|
2010-02-25 01:12:15 +00:00
|
|
|
# coding=utf8
|
|
|
|
|
2009-06-10 21:39:24 +00:00
|
|
|
import sleekxmpp
|
2009-06-03 22:56:51 +00:00
|
|
|
import logging
|
|
|
|
from optparse import OptionParser
|
|
|
|
import time
|
|
|
|
|
2010-02-27 02:02:08 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
if sys.version_info < (3,0):
|
2010-07-20 18:33:43 +00:00
|
|
|
reload(sys)
|
|
|
|
sys.setdefaultencoding('utf8')
|
2010-02-27 02:02:08 +00:00
|
|
|
|
2010-02-25 01:12:15 +00:00
|
|
|
|
2009-06-10 21:39:24 +00:00
|
|
|
class Example(sleekxmpp.ClientXMPP):
|
2010-07-20 18:33:43 +00:00
|
|
|
|
|
|
|
def __init__(self, jid, password):
|
|
|
|
sleekxmpp.ClientXMPP.__init__(self, jid, password)
|
|
|
|
self.add_event_handler("session_start", self.start)
|
|
|
|
self.add_event_handler("message", self.message)
|
|
|
|
|
|
|
|
def start(self, event):
|
|
|
|
self.getRoster()
|
|
|
|
self.sendPresence()
|
|
|
|
|
|
|
|
def message(self, msg):
|
|
|
|
msg.reply("Thanks for sending\n%(body)s" % msg).send()
|
2009-06-03 22:56:51 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2010-07-20 18:33:43 +00:00
|
|
|
#parse command line arguements
|
|
|
|
optp = OptionParser()
|
|
|
|
optp.add_option('-q','--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.INFO)
|
|
|
|
optp.add_option('-d','--debug', help='set logging to DEBUG', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO)
|
|
|
|
optp.add_option('-v','--verbose', help='set logging to COMM', action='store_const', dest='loglevel', const=5, default=logging.INFO)
|
|
|
|
optp.add_option("-j","--jid", dest="jid", help="JID to use")
|
|
|
|
optp.add_option("-p","--password", dest="password", help="password to use")
|
|
|
|
opts,args = optp.parse_args()
|
|
|
|
|
|
|
|
logging.basicConfig(level=opts.loglevel, format='%(levelname)-8s %(message)s')
|
|
|
|
xmpp = Example(opts.jid, opts.password)
|
|
|
|
xmpp.registerPlugin('xep_0030')
|
|
|
|
xmpp.registerPlugin('xep_0004')
|
|
|
|
xmpp.registerPlugin('xep_0060')
|
|
|
|
xmpp.registerPlugin('xep_0199')
|
|
|
|
|
|
|
|
# use this if you don't have pydns, and want to
|
|
|
|
# talk to GoogleTalk (e.g.)
|
|
|
|
# if xmpp.connect(('talk.google.com', 5222)):
|
|
|
|
if xmpp.connect():
|
|
|
|
xmpp.process(threaded=False)
|
|
|
|
print("done")
|
|
|
|
else:
|
|
|
|
print("Unable to connect.")
|