Skip to content

Instantly share code, notes, and snippets.

@sam-drew
Created December 20, 2019 16:01
Show Gist options
  • Select an option

  • Save sam-drew/9e7c8e37277f37224fc1905a8d663b66 to your computer and use it in GitHub Desktop.

Select an option

Save sam-drew/9e7c8e37277f37224fc1905a8d663b66 to your computer and use it in GitHub Desktop.
Convert string coordinates to a coord object.
import json
data = None
extractedData = []
with open("airport-codes_json.json", "r") as read_file:
data = json.load(read_file)
for item in data:
if item["iata_code"] != None and (item["type"] == "large_airport" or item["type"] == "medium_airport"):
extractedData.append(item)
for airport in extractedData:
coordString = airport["coordinates"]
result = [x.strip() for x in coordString.split(',')]
airport["coordinates"] = {
"lat": float(result[1]),
"lon": float(result[0]),
}
with open("iata_only_med_large_only.json", "w") as write_file:
json.dump(extractedData, write_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment