Skip to content

Instantly share code, notes, and snippets.

@mjg123
Last active April 10, 2018 17:08
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 mjg123/87a293996e04a2cfcda732b7970f0aee to your computer and use it in GitHub Desktop.
Save mjg123/87a293996e04a2cfcda732b7970f0aee to your computer and use it in GitHub Desktop.
Example fn code to query the OsloBysykkel API
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