Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python solution to the GoEuroTest
#!/usr/bin/env python
# encoding: utf-8
"""
Created by Christian Stade-Schuldt on 2013-11-12.
"""
import sys
import os
import csv
import json
import urllib
def main():
url = "http://pre.dev.goeuro.de:12345/api/v1/suggest/position/en/name/"
parameter = "ber"
response = urllib.urlopen(url+parameter)
data = json.loads(response.read())
results = []
for result in data["results"]:
_type = result["_type"]
_id = result["_id"]
_name = result["name"]
_latitude = result["geo_position"]["latitude"]
_longitude = result["geo_position"]["longitude"]
results.append([_type, _id, _name, _latitude, _longitude])
with open("output.csv", "wb") as f:
writer = csv.writer(f)
for result in results:
writer.writerow(result)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.