From 2a659eda8eb1c5a9c006a3b12f853fc7dc79a6a0 Mon Sep 17 00:00:00 2001
From: Dominic Kraemer
 <Dominic_Daniel.Kraemer@Student.Reutlingen-University.de>
Date: Thu, 20 Jun 2024 17:42:17 +0200
Subject: [PATCH] add basic python logic for the current_iss_location action

---
 rasa/actions/actions.py | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/rasa/actions/actions.py b/rasa/actions/actions.py
index 23dbb54..e82c283 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:
-- 
GitLab