-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSMCRunCommand.py
More file actions
66 lines (47 loc) · 1.92 KB
/
SMCRunCommand.py
File metadata and controls
66 lines (47 loc) · 1.92 KB
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
import telepot
from decouple import config
import os, sys, time, random, datetime
from Lab5015_utils import SMChiller
WORKING_DIR = "/home/cmsdaq/Programs/Lab5015Utils"
LOG_DIR = WORKING_DIR+"/Alarms"
os.chdir(WORKING_DIR)
if not os.path.exists(LOG_DIR):
os.mkdir(LOG_DIR)
tlog_file = open(LOG_DIR+"/SMCRunCommand.log", "a")
tlog_file.write('I am listening...\n')
tlog_file.flush()
def handle(msg):
SMC = SMChiller()
chat_id = msg['chat']['id']
command = msg['text']
tlog_file.write('Got command: %s\n' % command )
tlog_file.write(' from chat id = %s\n' % chat_id )
tlog_file.flush()
# if (chat_id == 145950543):
if (chat_id != 0):
# if (1):
if (command == '/press' or command == 'Press'):
my_press = SMC.read_meas_press()
bot.sendMessage(chat_id, "pressure is: %s MPa" % my_press)
elif (command == '/temp' or command == 'Temp'):
my_temp = SMC.read_meas_temp()
bot.sendMessage(chat_id, "temperature is: %s°C" % my_temp)
elif (command == '/state' or command == 'State'):
my_state = SMC.check_state()
bot.sendMessage(chat_id, "state is: %s" % my_state)
elif (command == '/how_is_life' or command == 'How is life?'):
my_press = SMC.read_meas_press()
my_temp = SMC.read_meas_temp()
bot.sendMessage(chat_id, "I am fine thanks")
bot.sendMessage(chat_id, "Pressure is %s MPa and water temp is %s°C" % (my_press, my_temp))
elif (command == '/commands' or command == 'commands'):
bot.sendMessage(chat_id, "Available commands are: /press, /temp, /state, /how_is_life")
else:
bot.sendMessage(chat_id, "I wish you a great day!")
else:
bot.sendMessage(chat_id, "I don't know you")
telegram_token = config('TELEGRAM_TOKEN')
bot = telepot.Bot(telegram_token)
bot.message_loop(handle)
while (1):
time.sleep(10)