forked from marksev1/Mycroft-SpaceLaunch-Skill
-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
74 lines (68 loc) · 2.97 KB
/
__init__.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
74
from ovos_workshop.intents import IntentBuilder
from ovos_workshop.skills import OVOSSkill
from ovos_workshop.decorators import intent_handler
import requests
from datetime import datetime, timedelta
from lingua_franca.format import nice_date, nice_duration
class SpaceLaunchSkill(OVOSSkill):
# https://www.rocketlaunch.live/api
# https://launchlibrary.net/
@intent_handler(
IntentBuilder("SpaceLaunchIntent").require("SpaceLaunchKeyword").
optionally('ExactLaunchKeyword').optionally("next"))
def handle_space_launch_intent(self, message):
try:
r = requests.get("https://launchlibrary.net/1.2/launch/next/1"
"").json()
dt = datetime.strptime(r['launches'][0]["windowstart"],
"%B %d, %Y %H:%M:%S UTC")
image = r['launches'][0]["rocket"]["imageURL"]
description = str(r['launches'][0]["missions"][0]["description"])
rocket = str(r['launches'][0]['rocket']['name'])
location = str(r['launches'][0]['location']['pads'][0]['name'])
now = datetime.now()
delta = dt - now
if delta <= timedelta(days=2):
date_time = nice_duration(delta, lang=self.lang, speech=True)
self.speak_dialog("space.launch.delta",
data={
'rocket': rocket,
'delta': date_time,
'location': location
})
else:
date_time = nice_date(dt, lang=self.lang, now=now)
self.speak_dialog("space.launch",
data={
'rocket': rocket,
'time': date_time,
'location': location
})
self.gui.show_image(
image,
caption=location,
title=rocket,
override_idle=True,
fill='PreserveAspectFit',
)
self.set_context("launch_description", description)
self.set_context("rocketPic", image)
self.set_context("rocket", rocket)
except Exception as e:
self.log.error(e)
self.speak_dialog("not.found")
@intent_handler(
IntentBuilder("SpaceLaunchMoreIntent").require("launch_description").
require("rocket").require("rocketPic").require('MoreKeyword'))
def handle_space_launch_desc_intent(self, message):
description = message.data["launch_description"]
rocket = message.data["rocket"]
image = message.data["rocketPic"]
self.speak(description)
self.gui.show_image(
image,
caption=description,
title=rocket,
override_idle=True,
fill='PreserveAspectFit',
)