-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfckeg.py
69 lines (55 loc) · 1.63 KB
/
nfckeg.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
import Notifications as noti
import Sensors as sen
import Database as db
from commandlist import CommandList
import time
import yaml
import json
class Nfckeg():
def __init__(self):
self.flow_near = None
self.flow_out = None
self.cl = CommandList()
self.config()
self.notify = []
self.notify.append(noti.MockObject(self.cfg))
self.notify.append(noti.TelegramChannel(self.cfg))
self.sensors = []
self.sensors.append(sen.Flow())
self.sensors.append(sen.NFC())
def dif_flow(self):
difference = self.flow_near - self.flow_out
return difference
def config(self):
with open("config.yaml") as f:
self.cfg = yaml.load(f)
self.token = self.cfg["telegram"]["token"]
def next_command(self):
try:
return self.cl.next()
except:
return (None, None)
def execute_command(self, command):
print "Will execute", command
words = command.split()
first_word = words[0]
rest_words = words[1:]
message = None
for a in self.sensors:
if a.is_for_you(first_word):
message = a.do(rest_words)
break
else:
print "No t'entenc"
return message
def mainloop(self):
chan, command = self.next_command()
if command:
response = self.execute_command(command)
chan.respond(response)
time.sleep(1)
self.update_channels()
if __name__ == "__main__"
print "Running!"
nfc = Nfckeg()
nfc.mainloop()