From 0318202aa556a6c0aaa415e0acf7b94a6c9955d2 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 10 Feb 2017 23:36:16 +0100 Subject: [PATCH] Added so you can add to cmd prompt if you want to filter out all other names than the name specified. --- homeCheck.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/homeCheck.py b/homeCheck.py index efc50df..4317527 100755 --- a/homeCheck.py +++ b/homeCheck.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 from socket import * -from pprint import pprint import json +from sys import argv # Set host name and port host = '10.0.0.41' @@ -10,13 +10,21 @@ port = 12001 clientSocket = socket(AF_INET, SOCK_DGRAM) -def main(): +def fetchHTimes(filter=None): clientSocket.sendto(b'get_times', (host, port)) message, address = clientSocket.recvfrom(1024) message = message.decode('utf-8') + for item in json.loads(message): - print(item['name'].ljust(10) + ': ' + item['time']) + if filter != None and item['name'].lower() == filter: + print(item['name'].ljust(10) +': '+ item['time']) + break + elif filter == None: + print(item['name'].ljust(10) +': '+ item['time']) clientSocket.close() if __name__ == '__main__': - main() \ No newline at end of file + if argv[-1][-3:] == '.py': + fetchHTimes() + else: + fetchHTimes(argv[-1]) \ No newline at end of file