From 851b2935ed05d32f29ebdaf919e258dafa6fb1b7 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 14 Jun 2021 08:48:59 -0400 Subject: [PATCH] initial add copied from gpredict --- groundstation/loc-add-foxtelem.py | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 groundstation/loc-add-foxtelem.py diff --git a/groundstation/loc-add-foxtelem.py b/groundstation/loc-add-foxtelem.py new file mode 100644 index 00000000..acd412bb --- /dev/null +++ b/groundstation/loc-add-foxtelem.py @@ -0,0 +1,45 @@ +# code based on https://developer.here.com/blog/understanding-geocoding-with-python +# +# copy or rename to loc.py and add api key + +import requests + +URL = "https://geocode.search.hereapi.com/v1/geocode" +print("In order to track satellites, we need to know your location\n") +print("You can enter your state or country or region\n") +print("as your exact location is not needed. \n\n") +location = input("Type your location: ") #taking user input +api_key = '' # Acquire from developer.here.com +PARAMS = {'apikey':api_key,'q':location} + +# sending get request and saving the response as response object +r = requests.get(url = URL, params = PARAMS) +data = r.json() + +#print(data) + +latitude = data['items'][0]['position']['lat'] +longitude = data['items'][0]['position']['lng'] + +print(latitude) +print(longitude) + +file = open(r"/home/pi/.config/Gpredict/MyLocation.qth","w+") + +str1 = "[QTH]\n" +str2 = "LOCATION=" + location + "\n" +str3 = "LAT=" + str(latitude) + "\n" +str4 = "LON=" + str(longitude) + "\n" +str5 = "ALT=0\n" +str6 = "WX=\n" +str7 = "QTH_TYPE=0\n" + +file.write(str1) +file.write(str2) +file.write(str3) +file.write(str4) +file.write(str5) +file.write(str6) +file.write(str7) + +file.close()