From 1eba5e9ea7990162bfc407dc557df14bf25d41d7 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Mon, 13 Nov 2017 10:09:12 +0100 Subject: don't send presence and only connect xmpp if there are new transactions --- transfers.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'transfers.py') diff --git a/transfers.py b/transfers.py index e3ee1a1..fbf72b6 100755 --- a/transfers.py +++ b/transfers.py @@ -80,19 +80,19 @@ for t in transactions: logging.info("Created %s", record.id) record.save() -cl = ClientXMPP(config['jabber']['jid'], config['jabber']['password']) +if len(new_transactions) > 0: + cl = ClientXMPP(config['jabber']['jid'], config['jabber']['password']) -def session_start(event): - cl.send_presence() - for t in new_transactions: - message = t.format_message() - cl.send_message(config['jabber']['recipient'], message, mtype='chat') - logging.info("Sent info %s", message) - cl.disconnect() + def session_start(event): + for t in new_transactions: + message = t.format_message() + cl.send_message(config['jabber']['recipient'], message, mtype='chat') + logging.info("Sent info %s", message) + cl.disconnect() -cl.add_event_handler('session_start', session_start) -cl.add_event_handler('killed', lambda *_: cl.loop.stop()) -cl.connect() -cl.process() + cl.add_event_handler('session_start', session_start) + cl.add_event_handler('killed', lambda *_: cl.loop.stop()) + cl.connect() + cl.process() -- cgit v1.2.1