Difference between revisions of "SpaceAPI"

From Fixme.ch
Jump to: navigation, search
(Description)
Line 5: Line 5:
 
**https://fixme.ch/status.json
 
**https://fixme.ch/status.json
 
* Provide a simple API to know whether the hackerspace is open or closed
 
* Provide a simple API to know whether the hackerspace is open or closed
* Implements the Space API
+
* Documentation to implements the SpaceAPI
 
** New website: http://spaceapi.net/
 
** New website: http://spaceapi.net/
 
** Old website: https://hackerspaces.nl/spaceapi/
 
** Old website: https://hackerspaces.nl/spaceapi/
 
** [http://openspace.slopjong.de/ API Validator]
 
** [http://openspace.slopjong.de/ API Validator]
 +
* App which implements it
 +
** http://spacestatus.bastinat0r.de/#fixme
 +
** http://spaceapi.net/app
  
 
== Components ==
 
== Components ==

Revision as of 10:08, 2 June 2014

Description

Components

Dummy script to lookup the status

#!/usr/bin/env python3
import urllib.request
import json
 
URL = "https://fixme.ch/cgi-bin/spaceapi.py"
 
def get_json():
	try:
		con = urllib.request.urlopen(URL)
		content = con.read()
		hs_json = json.loads(content.decode('utf8'))
		return hs_json
	except IOError:
		print("A network error occured sorry")
		exit(1)
	except ValueError:
		print("Malformatted json")
 
def print_info(hs_json):
	if hs_json['open']:
		print("OPENENENENEN")
		print("status is : {status}".format(**hs_json))
		print("the changes happens at {lastchange}".format(**hs_json))
		print("The duration is {duration} hours".format(**hs_json))
	else:
		print("The hackerspace is closed")
json = get_json()
try:
        print_info(json)
except:
        pass

Participant