-
Notifications
You must be signed in to change notification settings - Fork 0
/
homedata.py
31 lines (20 loc) · 930 Bytes
/
homedata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import requests, logging, json
class homedata:
def __init__(self, config):
self.config = config
def send(self, readings):
statIsActive = self.config["isActive"]
if statIsActive == "true" :
logger = logging.getLogger("growlab")
data = {"location":"growlab","table":[]}
pairs = readings.items()
for key, value in pairs:
if key != "time":
data["table"].append({"key" :key, "value": value})
logger.info("request: {} {}".format(self.config["url"], data))
try:
x = requests.post(self.config["url"], json.dumps(data))
except Exception as e:
logging.error("Error: {}".format(e))
#print the response text (the content of the requested file):
logger.info("response {}".format(x.text))