Last active
April 10, 2018 17:08
-
-
Save mjg123/87a293996e04a2cfcda732b7970f0aee to your computer and use it in GitHub Desktop.
Example fn code to query the OsloBysykkel API
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
import json | |
import urllib2 | |
import sys | |
try: | |
input = json.loads(''.join(sys.stdin.readlines()))['body'] | |
except: | |
input="" | |
if input == "": | |
input = "167" | |
input = input.strip() | |
opener = urllib2.build_opener() | |
opener.addheaders = [('Client-Identifier', 'f416cc3951533fc385acd670a0d0172d')] | |
content = opener.open('https://oslobysykkel.no/api/v1/stations').read() | |
bikestations = json.loads(content) | |
output = {} | |
for b in bikestations['stations']: | |
if str(b['id']) == input: | |
output = b | |
print(json.dumps({'body': json.dumps(output)})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment