From e0c8d75c2f180c3f988413d9359766b8641a71e8 Mon Sep 17 00:00:00 2001 From: Benajmyn Love Date: Tue, 24 Jul 2018 12:45:32 +1000 Subject: [PATCH] Initial Code Commit --- main.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..fd62e05 --- /dev/null +++ b/main.py @@ -0,0 +1,62 @@ +import urllib2 +import json +import ssl +import os +import time +from pprint import pprint +from win10toast import ToastNotifier + +toaster = ToastNotifier() + +myExtension = 1254 + +nocURL = "https://noc.ventraip.net.au/new/api.php" +context = ssl._create_unverified_context() + +phoneQueues = {"QUEUE618":"Synergy Sales","QUEUE285":"Ventra Sales","QUEUE384":"Synergy Technical","QUEUE286":"Ventra Billing","QUEUE284":"Ventra Technical"} + +ringing = False + +def getNOCData(URL): + data = urllib2.urlopen(URL, context=context) + jsonData = json.loads(data.read()) + #file = open('testData.json') + #jsonData = json.load(file) + return jsonData + +def amRinging(ring, queue): + global ringing + if ring == True: + toaster.show_toast(phoneQueues[queue], + "Is ringing :(", + icon_path=None, +# duration=20, + threaded=True) + ringing = False + +if __name__ == '__main__': +# while True: +# data = getNOCData(nocURL) +# pprint(data) + while True: + try: + data = getNOCData(nocURL) + #pprint(data["queues"]) + except urllib2.URLError, e: + print(str(e.reason)) + continue + + for queue in phoneQueues: + queueData = data["queues"][queue]["loggedIn"] + #print("The queue is %s" % phoneQueues[queue]) + for extension in queueData: + #print("\t%s" % extension) + if data["queues"][queue]["calls"] > 0: + if extension["extension"] == myExtension: + #print(extension["status"]) + if extension["status"] == 6: + ringing = True + else: + ringing = False + amRinging(ringing, queue) + time.sleep(1) \ No newline at end of file