diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-08 13:25:44 -0400 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-08 13:25:44 -0400 |
commit | 8864a4018c9b9088f330c3ef24ed7b5313ec36a2 (patch) | |
tree | 2fe858d60c8c0a41b97002216949097887652f82 /run/jabber.py | |
parent | 56a7f70965a17509898cf9e7eafb4e13208e5358 (diff) |
Added -j option to send jabber update messages.
Diffstat (limited to 'run/jabber.py')
-rw-r--r-- | run/jabber.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/run/jabber.py b/run/jabber.py new file mode 100644 index 0000000..c9dd097 --- /dev/null +++ b/run/jabber.py | |||
@@ -0,0 +1,40 @@ | |||
1 | #!/usr/bin/env python | ||
2 | import os | ||
3 | import sys | ||
4 | import xmpp | ||
5 | |||
6 | class Jabber(object): | ||
7 | def __init__(self, target): | ||
8 | self.target = target | ||
9 | self.client = self.__create_client() | ||
10 | |||
11 | def __create_client(self): | ||
12 | params = {} | ||
13 | conf_file = os.environ['HOME'] + '/.xsend' | ||
14 | |||
15 | if os.access(conf_file, os.R_OK): | ||
16 | for line in open(conf_file, 'r').readlines(): | ||
17 | key, val = line.strip().split('=', 1) | ||
18 | params[key.lower()] = val | ||
19 | |||
20 | for field in ['login', 'password']: | ||
21 | if field not in params.keys(): | ||
22 | with open(conf_file, 'wc') as f: | ||
23 | f.write('#LOGIN=romeo@montague.net\n#PASSWORD=juliet\n') | ||
24 | raise IOError("Please ensure the ~/.xsend file has valid "+\ | ||
25 | "credentials for sending messages.") | ||
26 | |||
27 | jid = xmpp.protocol.JID(params['login']) | ||
28 | client = xmpp.Client(jid.getDomain(), debug=[]) | ||
29 | |||
30 | client.connect(server=(jid.getDomain(), 5223)) | ||
31 | client.auth(jid.getNode(), params['password']) | ||
32 | |||
33 | sys.stderr.write(("Jabber client loaded. Add '%s' to your friends " + \ | ||
34 | "or Jabber messages will not send") % params['login']) | ||
35 | |||
36 | return client | ||
37 | |||
38 | def send(self, text): | ||
39 | message = xmpp.protocol.Message(to=self.target, body=text, typ='chat') | ||
40 | self.client.send(message) | ||