From 1594fa6e3677d248923940107657b49e8cb34558 Mon Sep 17 00:00:00 2001 From: Greg Sandstrom Date: Thu, 7 Mar 2024 12:08:46 -0800 Subject: [PATCH] add ctr temperature, units to all slackbot messages --- ssa/slackbot/slackbot.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ssa/slackbot/slackbot.py b/ssa/slackbot/slackbot.py index 045d9ee..59d1e3b 100644 --- a/ssa/slackbot/slackbot.py +++ b/ssa/slackbot/slackbot.py @@ -17,6 +17,10 @@ PUMP2_FLOW_QUERY = """ SELECT last(value) as value From Pump2 """ +TEMPERATURE_QUERY = """ +SELECT last(value) as value from ChannelWaterCTR +""" + class SlackBot: def __init__(self): @@ -39,16 +43,19 @@ class SlackBot: self.config["influxdb"].get("dbname", "paddle"), ) result1 = idb_client.query(PUMP1_FLOW_QUERY) - (pump1, time1) = self.parse_pump_query_result(result1, "Pump1") + (pump1, time1) = self.parse_query_result(result1, "Pump1") result2 = idb_client.query(PUMP2_FLOW_QUERY) - (pump2, time2) = self.parse_pump_query_result(result2, "Pump2") + (pump2, time2) = self.parse_query_result(result2, "Pump2") + result3 = idb_client.query(TEMPERATURE_QUERY) + (ctr_temp, time3) = self.parse_query_result(result3, "ChannelWaterCTR") idb_client.close() # post to slack channel # parse iso times and convert to local timezone dtime1 = dateutil.parser.isoparse(time1).astimezone() dtime2 = dateutil.parser.isoparse(time2).astimezone() - message = f"Pump1: {pump1:4.1f} ({dtime1.strftime('%d %b %Y, %I:%M%p')})\nPump2: {pump2:4.1f} ({dtime2.strftime('%d %b %Y, %I:%M%p')})" + dtime3 = dateutil.parser.isoparse(time3).astimezone() + message = f"Pump1: {pump1:4.1f}GPM ({dtime1.strftime('%d %b %Y, %I:%M%p')})\nPump2: {pump2:4.1f}GPM ({dtime2.strftime('%d %b %Y, %I:%M%p')})\nCTR Temperature: {ctr_temp:4.1f}C ({dtime3.strftime('%d %b %Y, %I:%M%p')})" json_message = { "channel": self.config["slack"]["channel_id"], @@ -63,7 +70,7 @@ class SlackBot: requests.post(url=post_url, headers=headers, json=json_message) - def parse_pump_query_result(self, result, name): + def parse_query_result(self, result, name): data = list(result.get_points(name))[0] value = data.get("value") time = data.get("time") -- 1.9.1