diff options
author | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-01-31 15:09:58 +0000 |
---|---|---|
committer | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-01-31 15:09:58 +0000 |
commit | d6458b66aab2b84ff7d5a800b1e603f25181d723 (patch) | |
tree | 60a5dee7263bde102c32aa1420ee6f2d9206733e /src/xmpppy-0.5.0rc1/doc/examples/xsend.py | |
parent | 98efd30d3077e12bef459dba2dff179302116a5d (diff) | |
download | poezio-d6458b66aab2b84ff7d5a800b1e603f25181d723.tar.gz poezio-d6458b66aab2b84ff7d5a800b1e603f25181d723.tar.bz2 poezio-d6458b66aab2b84ff7d5a800b1e603f25181d723.tar.xz poezio-d6458b66aab2b84ff7d5a800b1e603f25181d723.zip |
inclus xmppy0.5-RC1 avec les sources, sinon c'est chiant.
Diffstat (limited to 'src/xmpppy-0.5.0rc1/doc/examples/xsend.py')
-rwxr-xr-x | src/xmpppy-0.5.0rc1/doc/examples/xsend.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/xmpppy-0.5.0rc1/doc/examples/xsend.py b/src/xmpppy-0.5.0rc1/doc/examples/xsend.py new file mode 100755 index 00000000..59b202a9 --- /dev/null +++ b/src/xmpppy-0.5.0rc1/doc/examples/xsend.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +# $Id: xsend.py,v 1.8 2006/10/06 12:30:42 normanr Exp $ +import sys,os,xmpp,time + +if len(sys.argv) < 2: + print "Syntax: xsend JID text" + sys.exit(0) + +tojid=sys.argv[1] +text=' '.join(sys.argv[2:]) + +jidparams={} +if os.access(os.environ['HOME']+'/.xsend',os.R_OK): + for ln in open(os.environ['HOME']+'/.xsend').readlines(): + if not ln[0] in ('#',';'): + key,val=ln.strip().split('=',1) + jidparams[key.lower()]=val +for mandatory in ['jid','password']: + if mandatory not in jidparams.keys(): + open(os.environ['HOME']+'/.xsend','w').write('#Uncomment fields before use and type in correct credentials.\n#JID=romeo@montague.net/resource (/resource is optional)\n#PASSWORD=juliet\n') + print 'Please point ~/.xsend config file to valid JID for sending messages.' + sys.exit(0) + +jid=xmpp.protocol.JID(jidparams['jid']) +cl=xmpp.Client(jid.getDomain(),debug=[]) + +con=cl.connect() +if not con: + print 'could not connect!' + sys.exit() +print 'connected with',con +auth=cl.auth(jid.getNode(),jidparams['password'],resource=jid.getResource()) +if not auth: + print 'could not authenticate!' + sys.exit() +print 'authenticated using',auth + +#cl.SendInitPresence(requestRoster=0) # you may need to uncomment this for old server +id=cl.send(xmpp.protocol.Message(tojid,text)) +print 'sent message with id',id + +time.sleep(1) # some older servers will not send the message if you disconnect immediately after sending + +#cl.disconnect() |