Created
November 21, 2013 14:24
-
-
Save Tafkas/7582365 to your computer and use it in GitHub Desktop.
Python solution to the GoEuroTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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