From a0f3c7b30e71f9ba2be4379eabad0b66cf166041 Mon Sep 17 00:00:00 2001 From: Pascal <engelerp@phys.ethz.ch> Date: Tue, 23 Jul 2024 10:37:15 +0200 Subject: [PATCH] Added element communicator --- drivers/drivers/element.py | 23 +++++++++++++++++++++++ drivers/drivers/templog.dat | 2 +- drivers/multisampling/element.py | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 drivers/drivers/element.py create mode 100644 drivers/multisampling/element.py diff --git a/drivers/drivers/element.py b/drivers/drivers/element.py new file mode 100644 index 0000000..720490f --- /dev/null +++ b/drivers/drivers/element.py @@ -0,0 +1,23 @@ +import requests +import json + +with open('.secrets.json') as secrets_file: + secrets = json.load(secrets_file) + +def get_secrets(setting, secrets=secrets): + try: + return secrets[setting] + except KeyError: + print("Failed to load credentials.") + +class Element: + def __init__(self): + self.url = get_secrets("ELEMENT_URL") + + def warn(self, message): + myobj = {"text":message,"username":"Zygote"} + try: + requests.post(self.url, json=myobj) + #print(myobj["text"]) + except: + print("Failed to send message.") \ No newline at end of file diff --git a/drivers/drivers/templog.dat b/drivers/drivers/templog.dat index 790504b..9b8515f 100644 --- a/drivers/drivers/templog.dat +++ b/drivers/drivers/templog.dat @@ -1 +1 @@ -1721723768.1442149,30.998525,25.575567,31.34614,25.994017,33.898181 \ No newline at end of file +1721723827.9444673,30.996522,25.553679,31.375976,25.895765,34.028117 \ No newline at end of file diff --git a/drivers/multisampling/element.py b/drivers/multisampling/element.py new file mode 100644 index 0000000..720490f --- /dev/null +++ b/drivers/multisampling/element.py @@ -0,0 +1,23 @@ +import requests +import json + +with open('.secrets.json') as secrets_file: + secrets = json.load(secrets_file) + +def get_secrets(setting, secrets=secrets): + try: + return secrets[setting] + except KeyError: + print("Failed to load credentials.") + +class Element: + def __init__(self): + self.url = get_secrets("ELEMENT_URL") + + def warn(self, message): + myobj = {"text":message,"username":"Zygote"} + try: + requests.post(self.url, json=myobj) + #print(myobj["text"]) + except: + print("Failed to send message.") \ No newline at end of file -- GitLab