Commit 1594fa6e3677d248923940107657b49e8cb34558

Authored by Greg Sandstrom
1 parent 8be919fec4
Exists in main

add ctr temperature, units to all slackbot messages

Showing 1 changed file with 11 additions and 4 deletions Side-by-side Diff

ssa/slackbot/slackbot.py View file @ 1594fa6
... ... @@ -17,7 +17,11 @@
17 17 SELECT last(value) as value From Pump2
18 18 """
19 19  
  20 +TEMPERATURE_QUERY = """
  21 +SELECT last(value) as value from ChannelWaterCTR
  22 +"""
20 23  
  24 +
21 25 class SlackBot:
22 26 def __init__(self):
23 27 self.config = configparser.ConfigParser()
24 28  
25 29  
... ... @@ -39,16 +43,19 @@
39 43 self.config["influxdb"].get("dbname", "paddle"),
40 44 )
41 45 result1 = idb_client.query(PUMP1_FLOW_QUERY)
42   - (pump1, time1) = self.parse_pump_query_result(result1, "Pump1")
  46 + (pump1, time1) = self.parse_query_result(result1, "Pump1")
43 47 result2 = idb_client.query(PUMP2_FLOW_QUERY)
44   - (pump2, time2) = self.parse_pump_query_result(result2, "Pump2")
  48 + (pump2, time2) = self.parse_query_result(result2, "Pump2")
  49 + result3 = idb_client.query(TEMPERATURE_QUERY)
  50 + (ctr_temp, time3) = self.parse_query_result(result3, "ChannelWaterCTR")
45 51 idb_client.close()
46 52  
47 53 # post to slack channel
48 54 # parse iso times and convert to local timezone
49 55 dtime1 = dateutil.parser.isoparse(time1).astimezone()
50 56 dtime2 = dateutil.parser.isoparse(time2).astimezone()
51   - 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')})"
  57 + dtime3 = dateutil.parser.isoparse(time3).astimezone()
  58 + 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')})"
52 59  
53 60 json_message = {
54 61 "channel": self.config["slack"]["channel_id"],
... ... @@ -63,7 +70,7 @@
63 70  
64 71 requests.post(url=post_url, headers=headers, json=json_message)
65 72  
66   - def parse_pump_query_result(self, result, name):
  73 + def parse_query_result(self, result, name):
67 74 data = list(result.get_points(name))[0]
68 75 value = data.get("value")
69 76 time = data.get("time")