Download:
child 1:e73deb8e2462
0:6d62d30434ab
Anton Shestakov <engored@ya.ru>, Sun, 10 Jul 2016 10:58:40 +0000
(none)

1 файлов изменено, 54 вставок(+), 0 удалений(-) [+]
xmpp-headline.py file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/xmpp-headline.py Sun Jul 10 10:58:40 2016 +0000
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+from __future__ import print_function
+
+import sys
+
+import sleekxmpp
+
+
+class SendMsgBot(sleekxmpp.ClientXMPP):
+ def __init__(self, jid, password, recipient, efrom, esubject):
+ super(SendMsgBot, self).__init__(jid, password)
+
+ self.recipient = recipient
+ self.efrom = efrom
+ self.esubject = esubject
+
+ self.add_event_handler('session_start', self.start)
+
+ def start(self, event):
+ print('sending message...')
+ self.send_message(
+ mtype='headline',
+ mto=self.recipient,
+ msubject='New email: %s' % self.esubject,
+ mbody='%s from %s' % (self.esubject, self.efrom))
+ print('sent.')
+
+ print('disconnecting...')
+ self.disconnect(wait=True)
+ print('disconnected.')
+
+
+def main():
+ jid = 'emailbot@example.com'
+ password = 'hunter2'
+ to = 'john@example.com'
+
+ efrom = sys.argv[1] or '(unknown)'
+ esubject = sys.argv[2] or '(no subject)'
+
+ xmpp = SendMsgBot(jid, password, to, efrom, esubject)
+
+ print('connecting...')
+ if xmpp.connect():
+ print('processing...')
+ xmpp.process(block=True)
+ print('done.')
+ else:
+ print('connection failed.')
+ sys.exit(1)
+
+
+if __name__ == '__main__':
+ main()