Skip to content

Instantly share code, notes, and snippets.

@neilxp
Created April 26, 2013 02:59
Show Gist options
  • Save neilxp/5464805 to your computer and use it in GitHub Desktop.
Save neilxp/5464805 to your computer and use it in GitHub Desktop.
send weibo private message
#!/usr/bin/python
# $Id: weiboPm.py,v 1.0 2013/04/26 12:00:00 $
import sys,os,xmpp,time
USER=r"123456\40qq.com"
PASSWORD="secret"
RECEIVER=['123456@weibo.com']
def sendWeiboMsg(receivers, message):
jidparams={}
jid=xmpp.protocol.JID("xx@orehr.com")
jid.node=USER
jid.domain="weibo.com"
cl=xmpp.Client("xmpp.weibo.com",debug=[])
con=cl.connect()
if not con:
print 'could not connect!'
sys.exit()
print 'connected with',con
auth=cl.auth(jid.getNode(),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
for user in receivers:
id=cl.send(xmpp.protocol.Message(user, message))
print 'sent message with id', id
time.sleep(1) # some older servers will not send the message if you disconnect immediately after sending
if __name__ == "__main__":
if len(sys.argv) < 2:
print "Syntax: weiboPm.py message"
sys.exit(0)
message=' '.join(sys.argv[1:])
sendWeiboMsg(RECEIVER, message)
#cl.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment