From 67b656eae75be20bf036558db83c34ac10957f5f Mon Sep 17 00:00:00 2001 From: schneefux Date: Sun, 8 Nov 2015 10:46:58 +0100 Subject: created --- client.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 client.py (limited to 'client.py') diff --git a/client.py b/client.py new file mode 100755 index 0000000..34fb053 --- /dev/null +++ b/client.py @@ -0,0 +1,62 @@ +#!/usr/bin/python2 + +import tgl +import socket +import datetime + +IP_ADDR = "0.0.0.0" +FRIEND_1_ID = 00000000000 +FRIEND_2_ID = 00000000000 + + +def update_esp(what): + print("sending " + str(what)) + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((IP_ADDR, 23)) + sock.send(what) + sock.close() + + +# only send changes, prevents unnecessary wakeups +last_1 = b"" +last_2 = b"" + + +def on_news(peer): + then = peer.user_status["when"] + now = datetime.datetime.now() + + if (now - then).seconds < 1 * 60 or \ + then > now: + # `when` in the future means online right now + if peer.id == FRIEND_1_ID and last_i != b"B": + update_esp(b"B") + else: + if peer.id == FRIEND_2_ID and last_t != b"A": + update_esp(b"A") + else: + if peer.id == FRIEND_1_ID and last_i != b"b": + update_esp(b"b") + else: + if peer.id == FRIEND_2_ID and last_t != b"a": + update_esp(b"a") + + +def contact_list_cb(success, peer_list): + if success: + for peer in peer_list: + on_news(peer) + + +last_run = datetime.datetime(1970, 1, 1) + + +def on_loop(): + global last_run + # update every two minutes + if (datetime.datetime.now() - last_run).seconds > 1 * 60: + last_run = datetime.datetime.now() + tgl.get_contact_list(contact_list_cb) + + +tgl.set_on_loop(on_loop) -- cgit v1.3.1