-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
78 lines (63 loc) · 1.99 KB
/
main.py
File metadata and controls
78 lines (63 loc) · 1.99 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
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import time
import os
import sys
import json
from raven import Client
try:
import a00_command
except ImportError:
BASE_DIR = os.path.dirname(__file__)
SRC_DIR = os.path.join(BASE_DIR, "src")
sys.path.insert(0, SRC_DIR)
import a00_command
try:
import RPi.GPIO as gpio
except ImportError:
import a00_command.libs.dummy_gpio as gpio
from a00_command import Commander
from a00_command.libs.test_lib import say
from a00_command.libs.admin_lib import reboot
from a00_command.libs.recording_lib import start_recording, stop_recording
CREDS_PATH = os.environ["CREDENTIALS_PATH"]
GOOGLE_API_KEY = os.environ["GOOGLE_API_KEY"]
CUSTOM_TOKEN_URL = os.environ["FIREBASE_CUSTOM_TOKEN_URL"]
AUTH_DOMAIN = os.environ["FIREBASE_AUTH_DOMAIN"]
DB_URL = os.environ["FIREBASE_DB_URL"]
SENTRY_URL = os.environ.get("SENTRY_URL")
def main():
print "command starting"
# read in the credentials from file
with open(CREDS_PATH) as f:
creds = json.loads(f.read())
# make one
commander = Commander(creds,
GOOGLE_API_KEY,
CUSTOM_TOKEN_URL,
AUTH_DOMAIN,
DB_URL)
# add a function to be called by the commander
commander.add_function("say", say)
commander.add_function("reboot", reboot)
commander.add_function("start_recording", start_recording)
commander.add_function("stop_recording", stop_recording)
# start it
commander.start()
time.sleep(2)
sentry_client = Client(SENTRY_URL) if SENTRY_URL is not None else None
while True:
try:
# ask it to process any waiting messages
commander.tick(sentry_client)
time.sleep(0.5)
except KeyboardInterrupt:
commander.stop()
gpio.cleanup()
break
except SystemExit:
# stop it
commander.stop()
gpio.cleanup()
break
if __name__ == "__main__":
main()