-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
53 lines (44 loc) · 1.4 KB
/
app.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
import time
import re
from printer import Printer
import datetime
#from slack import RTMClient
from slack_sdk.rtm_v2 import RTMClient
import os
import threading
printers = []
# instantiate Slack client
rtm = None
if "SLACK_BOT_TOKEN" in os.environ:
print("Starting Slackbot")
rtm = RTMClient(token=os.environ["SLACK_BOT_TOKEN"])
if rtm:
@rtm.on("message")
def handle(client: RTMClient, event: dict):
if 'druckerstatus' in event['text']:
reply = ""
for p in printers:
reply += p.get_status() + "\r\n"
client.web_client.chat_postMessage(
channel=event['channel'],
#thread_ts = event['ts'],
text=str(reply)
)
def rtm_start():
if rtm:
rtm.start()
t1 = threading.Thread(name='slack-daemon', target=rtm_start)
t1.setDaemon(True)
t1.start()
printers.append(Printer("Prusa 1", "/dev/serial/by-id/usb-Prusa_Research__prusa3d.com__Original_Prusa_i3_MK3_CZPX3119X004XK40396-if00"))
printers.append(Printer("Prusa 2", "/dev/serial/by-id/usb-Prusa_Research__prusa3d.com__Original_Prusa_i3_MK3_CZPX0219X004XK03946-if00"))
printers.append(Printer("Prusa 3", "/dev/serial/by-id/usb-Prusa_Research__prusa3d.com__Original_Prusa_i3_MK3_CZPX1719X004XK22415-if00"))
last_check = datetime.datetime.now()
while True:
for p in printers:
p.process()
if (datetime.datetime.now() - last_check).seconds > 10:
last_check = datetime.datetime.now()
for p in printers:
print(p.get_status())
time.sleep(1)