Modified example to take JID and password on command line
This commit is contained in:
parent
ca2c421e6c
commit
66e92c6c9f
2 changed files with 40 additions and 32 deletions
3
INSTALL
3
INSTALL
|
@ -6,3 +6,6 @@ python3 setup.py install
|
||||||
|
|
||||||
Root install:
|
Root install:
|
||||||
sudo python3 setup.py install
|
sudo python3 setup.py install
|
||||||
|
|
||||||
|
To test:
|
||||||
|
python example.py -v -j [USER@example.com] -p [PASSWORD]
|
||||||
|
|
69
example.py
69
example.py
|
@ -8,41 +8,46 @@ import time
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3,0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
|
||||||
|
|
||||||
class Example(sleekxmpp.ClientXMPP):
|
class Example(sleekxmpp.ClientXMPP):
|
||||||
|
|
||||||
def __init__(self, jid, password):
|
def __init__(self, jid, password):
|
||||||
sleekxmpp.ClientXMPP.__init__(self, jid, password)
|
sleekxmpp.ClientXMPP.__init__(self, jid, password)
|
||||||
self.add_event_handler("session_start", self.start)
|
self.add_event_handler("session_start", self.start)
|
||||||
self.add_event_handler("message", self.message)
|
self.add_event_handler("message", self.message)
|
||||||
|
|
||||||
def start(self, event):
|
def start(self, event):
|
||||||
self.getRoster()
|
self.getRoster()
|
||||||
self.sendPresence()
|
self.sendPresence()
|
||||||
|
|
||||||
def message(self, msg):
|
def message(self, msg):
|
||||||
msg.reply("Thanks for sending\n%(body)s" % msg).send()
|
msg.reply("Thanks for sending\n%(body)s" % msg).send()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#parse command line arguements
|
#parse command line arguements
|
||||||
optp = OptionParser()
|
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('-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('-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('-v','--verbose', help='set logging to COMM', action='store_const', dest='loglevel', const=5, default=logging.INFO)
|
||||||
optp.add_option("-c","--config", dest="configfile", default="config.xml", help="set config file to use")
|
optp.add_option("-j","--jid", dest="jid", help="JID to use")
|
||||||
opts,args = optp.parse_args()
|
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('user@gmail.com/sleekxmpp', 'password')
|
logging.basicConfig(level=opts.loglevel, format='%(levelname)-8s %(message)s')
|
||||||
xmpp.registerPlugin('xep_0030')
|
xmpp = Example(opts.jid, opts.password)
|
||||||
xmpp.registerPlugin('xep_0004')
|
xmpp.registerPlugin('xep_0030')
|
||||||
xmpp.registerPlugin('xep_0060')
|
xmpp.registerPlugin('xep_0004')
|
||||||
xmpp.registerPlugin('xep_0199')
|
xmpp.registerPlugin('xep_0060')
|
||||||
if xmpp.connect(('talk.google.com', 5222)):
|
xmpp.registerPlugin('xep_0199')
|
||||||
xmpp.process(threaded=False)
|
|
||||||
print("done")
|
# use this if you don't have pydns, and want to
|
||||||
else:
|
# talk to GoogleTalk (e.g.)
|
||||||
print("Unable to connect.")
|
# if xmpp.connect(('talk.google.com', 5222)):
|
||||||
|
if xmpp.connect():
|
||||||
|
xmpp.process(threaded=False)
|
||||||
|
print("done")
|
||||||
|
else:
|
||||||
|
print("Unable to connect.")
|
||||||
|
|
Loading…
Reference in a new issue