diff --git a/groundstation/loc.py b/groundstation/loc.py new file mode 100644 index 00000000..1a881b3c --- /dev/null +++ b/groundstation/loc.py @@ -0,0 +1,38 @@ +# code based on https://developer.here.com/blog/understanding-geocoding-with-python + +import requests + +URL = "https://geocode.search.hereapi.com/v1/geocode" +location = input("Enter the location here: ") #taking user input +api_key = 'EabUlpQK8GcVVEMs2OLI0Bdb6A9Wj_yeli6d4Wwe8u0' # 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() + +latitude = data['items'][0]['position']['lat'] +longitude = data['items'][0]['position']['lng'] + +print(latitude) +print(longitude) + +file = open(r".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()