Skip to content

Instantly share code, notes, and snippets.

@Tafkas
Created November 21, 2013 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tafkas/7582365 to your computer and use it in GitHub Desktop.
Save Tafkas/7582365 to your computer and use it in GitHub Desktop.
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