File tree 2 files changed +51
-0
lines changed
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ # ISS Location
2
+
3
+ This scripted connector gets the location from the International Space Station from a public API and stores the coordinates in an element.
Original file line number Diff line number Diff line change
1
+ import requests
2
+ import json
3
+ from datetime import datetime
4
+
5
+ def fetch_iss_location ():
6
+ try :
7
+ response = requests .get ("http://api.open-notify.org/iss-now.json" )
8
+ if response .status_code == 200 :
9
+ data = response .json ()
10
+ timestamp = datetime .utcfromtimestamp (data ["timestamp" ]).strftime ('%Y-%m-%d %H:%M:%S' )
11
+ latitude = float (data ["iss_position" ]["latitude" ])
12
+ longitude = float (data ["iss_position" ]["longitude" ])
13
+
14
+ location = {
15
+ "date_time" : timestamp ,
16
+ "latitude" : latitude ,
17
+ "longitude" : longitude ,
18
+ "connectors" : {"connectorType" : "ISS_Tracker" }
19
+ }
20
+
21
+ return {"isslocation" : [location ]}
22
+ else :
23
+ print ("Failed to fetch ISS position" )
24
+ return None
25
+ except Exception as e :
26
+ print (f"Error: { e } " )
27
+ return None
28
+
29
+ def send_data_to_dataminer (data ):
30
+ if data :
31
+ url = "http://localhost:34567/api/data/parameters"
32
+ header_params = {
33
+ "identifier" : "ISS_Tracker" ,
34
+ "type" : "ISS_Tracker"
35
+ }
36
+
37
+ try :
38
+ response = requests .put (url , headers = header_params , json = data )
39
+ if response .status_code == 200 :
40
+ print ("Data successfully sent to DataMiner" )
41
+ else :
42
+ print (f"Failed to send data: { response .status_code } " )
43
+ except Exception as e :
44
+ print (f"Error sending data: { e } " )
45
+
46
+ if __name__ == "__main__" :
47
+ iss_data = fetch_iss_location ()
48
+ send_data_to_dataminer (iss_data )
You can’t perform that action at this time.
0 commit comments