-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction-overhead-handler.py
More file actions
executable file
·35 lines (26 loc) · 1.06 KB
/
action-overhead-handler.py
File metadata and controls
executable file
·35 lines (26 loc) · 1.06 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
#!/usr/bin/env python3
from hermes_python.hermes import Hermes
from overhead import Aircraft, get_aircrafts
def make_speech_output(aircraft: Aircraft) -> str:
return '{}, {}.\n{}. Heading {}.\nFrom "{}", to "{}".'.format(
aircraft.airline,
" ".join(aircraft.flight_no[2:]),
aircraft.model_speech,
aircraft.direction,
aircraft.orig_speech,
aircraft.dest_speech,
)
def subscribe_intent_callback(hermes, intentMessage) -> bool:
message = ""
# TODO: read this from a config file
aircrafts = get_aircrafts("47.83,47.40,-123.08,-121.48")
if aircrafts:
message += "I have identified {} aircraft.\n\n".format(len(aircrafts))
for aircraft in aircrafts:
message += make_speech_output(aircraft) + "\n\n"
if not message:
message = "Sorry, no aircraft found."
return hermes.publish_end_session(intentMessage.session_id, message.encode())
with Hermes(b"localhost:1883") as h:
h.subscribe_intent(b"coops:whatPlanesAreOverhead", subscribe_intent_callback)
h.start()