#!/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)