Initial commit

This commit is contained in:
Malte Münch 2020-01-26 19:04:52 +01:00
commit b4259d74a1
2 changed files with 52 additions and 0 deletions

52
get_coordinates.py Executable file
View File

@ -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")

BIN
locations.bin Normal file

Binary file not shown.