commit b4259d74a1dadf10a6111b3680d6db872061e210 Author: Malte Münch Date: Sun Jan 26 19:04:52 2020 +0100 Initial commit diff --git a/get_coordinates.py b/get_coordinates.py new file mode 100755 index 0000000..260464f --- /dev/null +++ b/get_coordinates.py @@ -0,0 +1,52 @@ +#!/usr/bin/python +import requests, json, pickle, os.path + +URL = "https://directory.spaceapi.io/" +NORTHERNMOST = 55.05 +EASTERNMOST = 15.033333 +SOUTHERNMOST = 47.270108 +WESTERNMOST = 5.866667 +locations = {} +if os.path.isfile('locations.bin'): + print ("using offline data...") + with open("locations.bin", "rb") as f: + locations = pickle.load(f) +else: + print ("offline data not available, downloading...,") + r = requests.get(url = URL) + data = r.json() + for space in data: + spacerequest = None + try: + spacerequest = requests.get(url = data[space], timeout=1) + except requests.exceptions.RequestException as e: # This is the correct syntax + continue + try: + spacedata = spacerequest.json() + except json.JSONDecodeError as jde: + continue + if "location" in spacedata: + if "lat" in spacedata["location"]: + lat = spacedata["location"]["lat"] + lon = spacedata["location"]["lon"] + locations[space] = [float(lat), float(lon)] + + for space in locations: + print (space + " " + str(locations[space])) + with open("locations.bin", "wb") as f: + pickle.dump(locations, f, pickle.HIGHEST_PROTOCOL) +print ("Removing non-german points...") +nongerman_locations = locations.copy() +for space in locations: + if locations[space][0] > NORTHERNMOST: + del nongerman_locations[space] + print ("kicked " + space + " too far north") + elif locations[space][0] < SOUTHERNMOST: + del nongerman_locations[space] + print ("kicked " + space + " too far south") + elif locations[space][1] < WESTERNMOST: + del nongerman_locations[space] + print ("kicked " + space + " too far west") + elif locations[space][1] > EASTERNMOST: + del nongerman_locations[space] + print ("kicked " + space + " too far east") diff --git a/locations.bin b/locations.bin new file mode 100644 index 0000000..f47092e Binary files /dev/null and b/locations.bin differ