#!/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")