-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrowbot.py
100 lines (94 loc) · 3.63 KB
/
growbot.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Sooo... these are my bots, will make a clean slate for u once I have time. -rbckman
import time
import logging
import requests
import subprocess
import glob
import os
from datetime import datetime
def bot(log, botapi, botstatus, room, client):
try:
laststatus, freqstatus, lastpic = botstatus
except:
laststatus = time.time()
freqstatus = 14400
lastpic = ''
msg = ''
# put your bot scripts here! the ones here now are my bots, should make an empty plate for u.
# if you need to get information from an api put the key in /.matrixchat/config.ini file like this
# oou and bot script wont run without it at the moment
# [botapi]
# botapi = key
#growbot
if (time.time() - laststatus > freqstatus) or ('growbot status' in log):
laststatus = time.time()
try:
list_of_files = glob.glob('/home/pi/camera/*')
newpic = max(list_of_files, key=os.path.getctime)
if newpic != lastpic:
with open('/home/pi/growbox.jpeg', 'rb') as image:
f = image.read()
imageurl = client.upload(f, 'image/jpeg',)
room.send_image(imageurl, 'mmm')
lastpic = newpic
except:
msg = 'growbot: not feeling ok, chack logs..'
logging.exception('')
try:
with open('/home/pi/growbox/readings', 'r') as p:
sensor = p.read().splitlines()[0]
except:
sensor = ''
try:
with open('/home/pi/growbox/fan', 'r') as f:
fan = f.read().splitlines()[0]
except:
fan = ''
try:
with open('/home/pi/growbox/lights', 'r') as f:
lights = f.read().splitlines()[0]
except:
lights = ''
msg = 'growbot: heres my status ' + sensor + ' lights:' + lights + ' fan:' + fan
elif 'growbot freq' in log:
try:
freqstatus = int(log.split("freq",1)[1])
msg = 'growbot: frequensy set to ' + str(freqstatus) + ' sec'
except:
msg = 'growbot: something funkky.. seconds right?'
logging.exception('')
elif 'growbot lights' in log:
try:
lightsstatus = log.split("lights",1)[1].strip()
with open('/home/pi/growbox/lights', 'w') as f:
f.write(lightsstatus)
msg = 'growbot: okey, turning lights ' + lightsstatus
except:
msg = 'growbot: not feeling ok, chack logs..'
logging.exception('')
elif 'growbot mist' in log:
try:
mist = log.split("mist",1)[1].strip()
mist = mist.strip(' ')
mist = mist.split(' ',1)
with open('/home/pi/growbox/humidifier', 'w') as f:
for a in mist:
f.write(a + '\n')
msg = 'growbot: okey, misting every ' + mist[0] + ' min for ' + mist[1] + ' seconds'
except:
msg = 'growbot: needs to be intervall in minutes and then for how long in seconds'
logging.exception('')
elif 'growbot fan' in log:
try:
fanstatus = log.split("fan",1)[1].strip()
with open('/home/pi/growbox/fan', 'w') as f:
f.write(fanstatus)
msg = 'growbot: okey, turning fan ' + fanstatus
except:
msg = 'growbot: not feeling ok, chack logs..'
elif 'growbot help' in log:
msg = 'growbot: Hi, u can has shrooms, ask my status, turn on/off lights or fan'
botstatus = laststatus, freqstatus, lastpic
return(msg, botstatus)