Last active
January 7, 2019 19:33
-
-
Save sbrl/cec59bb34fe3d2154f6964fe27da8d90 to your computer and use it in GitHub Desktop.
[xsend.py] A cleaned-up version of http://xmpppy.sourceforge.net/examples/xsend.py. Requires the "xmpppy" package - which is installable via pip.
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
#!/usr/bin/env python3 | |
# $Id: xsend.py,v 1.8 2006/10/06 12:30:42 normanr Exp $ | |
# Edited & cleaned up by Starbeamrainbowlabs <[email protected]> | |
import sys | |
import os | |
import time | |
import xmpp | |
if len(sys.argv) < 2: | |
print("Syntax: xsend JID text") | |
sys.exit(0) | |
tojid = sys.argv[1] | |
text = " ".join(sys.argv[2:]) | |
############################################################################### | |
class Settings(): | |
"""docstring for Settings.""" | |
def __init__(self): | |
super(Settings, self).__init__() | |
self.jid = os.environ.get("XMPP_JID") | |
self.password = os.environ.get("XMPP_PASSWORD") | |
if not self.jid: | |
print("Error: No login JID found in the XMPP_JID environment variable.") | |
sys.exit() | |
if not self.password: | |
print("Error: No password found in the XMPP_PASSWORD environment variable.") | |
sys.exit() | |
settings = Settings() | |
############################################################################### | |
jid = xmpp.protocol.JID(settings["jid"]) | |
client = xmpp.Client(jid.getDomain(), debug=[]) | |
con = client.connect() | |
if not con: | |
print("Error: Could not connect!") | |
sys.exit() | |
print("[xsend] Connected with", con) | |
auth = client.auth(jid.getNode(), settings["password"], resource=jid.getResource()) | |
if not auth: | |
print("Error: Failed to authenticate.") | |
sys.exit() | |
print("[xsend] Authenticated using", auth) | |
# client.SendInitPresence(requestRoster=0) # you may need to uncomment this for old server | |
id = client.send(xmpp.protocol.Message(tojid, text)) | |
print("[xsend] Sent message with id", id) | |
time.sleep(1) # some older servers will not send the message if you disconnect immediately after sending | |
# client.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment