From 79579a20d733f8befb2d9ca8f0639e05ab1c9be3 Mon Sep 17 00:00:00 2001 From: Marcel Nijenhof Date: Tue, 18 May 2021 12:45:05 +0200 Subject: [PATCH] Fix verwijderen array --- ddapioper.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/ddapioper.py b/ddapioper.py index 253c960..291e29c 100644 --- a/ddapioper.py +++ b/ddapioper.py @@ -270,7 +270,12 @@ Note: """ for e in self.result()["events"]: dt = isoparse(e["timeStamp"]) - p = e["aspects"][index]["points"][0] + if "value" in e: + p = e + elif "aspects" in e: + p = e["aspects"][index]["points"][0] + else: + raise() v = p.get("value", None) q = p.get("quality", None) a = p.get("additionalInfo", None) @@ -317,8 +322,10 @@ Returns the result set as string in the sip format! r = "!" sep = " " for e in self.result()["events"]: - v = e["aspects"][index]["points"][0]["value"] - q = e["aspects"][index]["points"][0]["quality"] + if "aspects" in e: + e = e["aspects"][index]["points"][0] + v = e["value"] + q = e["quality"] r += "%s%i/%i" % (sep, v, q) sep = ";" return(r) @@ -332,5 +339,20 @@ Exception class to use on http errors. def __init__(self, code): self.code = code + def __str__(self): + return("Code: %s" % self.code) + +class ddApiOperJsonError(Exception): + """ +Class ddApiOperJsonError + +Exception class to use on json errors. +""" + def __init__(self, json): + self.json = json + + def __str__(self): + return("Parse error in: %s" % self.json) + if __name__ == "__main__": pass