-
Notifications
You must be signed in to change notification settings - Fork 0
/
TopLevelCloud.py
73 lines (64 loc) · 1.99 KB
/
TopLevelCloud.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
from time import sleep
import pyrebase
import os
#import soco
flag=0
#speaker = soco.discovery.any_soco()
#device = soco.discovery.any_soco()
#speakers = list(soco.discover())
#speaker = speakers[0]
#speaker = soco.SoCo('192.168.137.58')
#print(speaker)
#print(device)
#print("Discovered Sonos")
#speaker.get_current_track_info()
config = {
"apiKey": "MyAUTH",
"authDomain": "projectId.firebaseapp.com",
"databaseURL": "https://everythingwand-default-rtdb.firebaseio.com/",
"storageBucket": "projectId.appspot.com",
}
def stream_handler(message):
global flag
#global speaker
if (flag==0):
flag=1
print("Ignored first iteration")
return 6
print("Command " + str(message['data']))
if message['data'] == 3:
print("Netflix request")
#attNum = db.child("Attribute").get().val()
#print(attNum)
#if os.path.exists("attribute.txt"):
#print("It exists")
# os.remove("attribute.txt")
# f=open("attribute.txt", "w")
# f.write(str(attNum))
# f.close()
#exec(open("./openNetflix.py").read())
elif message['data'] == 0:
print("Text Boss")
exec(open("./sms.py").read())
elif message['data'] == 1:
print("Order Pizza")
attNum = db.child("Attribute").get().val()
#print(attNum)
if os.path.exists("attribute.txt"):
#print("It exists")
os.remove("attribute.txt")
f=open("attribute.txt", "w")
f.write(str(attNum))
f.close()
exec(open("./orderDominos.py").read())
elif message['data'] == 2:
#global speaker
print("Play/pause music")
#speaker.get_current_transport_info()
#if speaker.get_current_transport_info()['current_transport_state'] == "PLAYING":
# speaker.pause()
#else:
# speaker.play()
firebase = pyrebase.initialize_app(config)
db = firebase.database()
my_stream=db.child("Command").stream(stream_handler)