diff --git a/rasa/actions/actions.py b/rasa/actions/actions.py index 23dbb5461dfaa4b890fb30a9c84520236f0ed7e0..e82c283ac1f6d7fbe5091248afee91db203480cb 100644 --- a/rasa/actions/actions.py +++ b/rasa/actions/actions.py @@ -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: