Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Space Station Chatbot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dominic Daniel Krämer
Space Station Chatbot
Commits
4e9fbee4
Commit
4e9fbee4
authored
11 months ago
by
Dominic Krämer
Browse files
Options
Downloads
Patches
Plain Diff
improve rasa api logic
parent
f50555de
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rasa/actions/actions.py
+60
-22
60 additions, 22 deletions
rasa/actions/actions.py
with
60 additions
and
22 deletions
rasa/actions/actions.py
+
60
−
22
View file @
4e9fbee4
...
...
@@ -4,8 +4,59 @@ from rasa_sdk import Action, Tracker
from
rasa_sdk.executor
import
CollectingDispatcher
import
os.path
import
urllib.request
from
datetime
import
datetime
filepath
=
"
../data/iss-location.txt
"
url
=
"
https://nasa-public-data.s3.amazonaws.com/iss-coords/current/ISS_OEM/ISS.OEM_J2K_EPH.txt
"
def
download_file
():
# download (and replace) file
if
os
.
path
.
isfile
(
filepath
):
os
.
remove
(
filepath
)
urllib
.
request
.
urlretrieve
(
url
,
filepath
)
def
find_location
(
timestamp
):
file
=
open
(
filepath
,
"
r
"
)
smaller_entry
=
""
bigger_entry
=
""
values
=
[
int
(
timestamp
[:
4
]),
# year
int
(
timestamp
[
5
:
7
]),
# month
int
(
timestamp
[
8
:
10
]),
# day
int
(
timestamp
[
11
:
13
]),
# hour
int
(
timestamp
[
14
:
16
])
# minute
]
starting_line_found
=
False
index
=
1
for
line
in
file
:
if
not
starting_line_found
:
if
"
COMMENT End sequence of events
"
in
line
:
starting_line_found
=
True
else
:
values_line
=
[
int
(
line
[:
4
]),
int
(
line
[
5
:
7
]),
int
(
line
[
8
:
10
]),
int
(
line
[
11
:
13
]),
int
(
line
[
14
:
16
])]
i
=
0
while
i
<=
4
:
if
values
[
i
]
>
values_line
[
i
]:
smaller_entry
=
line
break
elif
values
[
i
]
<
values_line
[
i
]:
bigger_entry
=
line
break
i
+=
1
if
bigger_entry
!=
""
:
break
index
+=
1
if
smaller_entry
==
""
:
return
bigger_entry
return
smaller_entry
class
ActionCurrentIssLocation
(
Action
):
...
...
@@ -16,26 +67,14 @@ class ActionCurrentIssLocation(Action):
tracker
:
Tracker
,
domain
:
Dict
[
Text
,
Any
])
->
List
[
Dict
[
Text
,
Any
]]:
# download (and replace) file
if
os
.
path
.
isfile
(
filepath
):
os
.
remove
(
filepath
)
urllib
.
request
.
urlretrieve
(
"
https://nasa-public-data.s3.amazonaws.com/iss-coords/current/ISS_OEM/ISS.OEM_J2K_EPH.txt
"
,
filepath
)
print
(
os
.
path
.
abspath
(
__file__
))
file
=
open
(
filepath
,
"
r
"
)
end_reached
=
False
location
=
""
for
line
in
file
:
if
end_reached
:
location
=
line
break
if
"
COMMENT End sequence of events
"
in
line
:
end_reached
=
True
download_file
()
location
=
find_location
(
str
(
datetime
.
now
()))
dispatcher
.
utter_message
(
text
=
"
location:
"
+
location
)
dispatcher
.
utter_message
(
text
=
f
"
location:
{
location
}
"
)
return
[]
class
ActionFutureIssLocation
(
Action
):
def
name
(
self
)
->
Text
:
...
...
@@ -45,15 +84,14 @@ class ActionFutureIssLocation(Action):
tracker
:
Tracker
,
domain
:
Dict
[
Text
,
Any
])
->
List
[
Dict
[
Text
,
Any
]]:
# download (and replace) file
if
os
.
path
.
isfile
(
"
../../api-data/iss-location.txt
"
):
os
.
remove
(
"
../../api-data/iss-location.txt
"
)
urllib
.
request
.
urlretrieve
(
"
https://nasa-public-data.s3.amazonaws.com/iss-coords/current/ISS_OEM/ISS.OEM_J2K_EPH.txt
"
,
"
text.txt
"
)
download_file
()
if
(
len
(
tracker
.
latest_message
[
'
entities
'
])
==
0
):
dispatcher
.
utter_message
(
text
=
"
I
'
m sorry, but I didn
'
t understand your formatting. Please try again.
"
)
else
:
dispatcher
.
utter_message
(
text
=
"
[Placeholder for the ISS location at:
"
+
tracker
.
latest_message
[
'
entities
'
][
0
][
'
value
'
]
+
"
]
"
)
entity
=
tracker
.
latest_message
[
'
entities
'
][
0
][
'
value
'
]
location
=
find_location
(
entity
)
dispatcher
.
utter_message
(
text
=
f
"
location:
{
location
}
"
)
return
[]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment