Skip to content
Snippets Groups Projects
Commit 2a659eda authored by Dominic Daniel Krämer's avatar Dominic Daniel Krämer
Browse files

add basic python logic for the current_iss_location action

parent 0e83d4f7
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,10 @@ from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
import os.path
import urllib.request
filepath = "../data/iss-location.txt"
class ActionCurrentIssLocation(Action):
......@@ -12,8 +15,24 @@ class ActionCurrentIssLocation(Action):
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
dispatcher.utter_message(text="[Placeholder for the current ISS location]")
# 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
dispatcher.utter_message(text="location: " + location)
return []
......@@ -26,6 +45,11 @@ 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")
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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment