Difference between revisions of "SpaceAPI"

From Fixme.ch
Jump to: navigation, search
(Components)
(Components)
Line 12: Line 12:
 
== Components ==
 
== Components ==
 
* [https://github.com/fixme-lausanne/Twitter-Hackerspace-Status Sources on Github]
 
* [https://github.com/fixme-lausanne/Twitter-Hackerspace-Status Sources on Github]
* Python script on fixme.ch that serves the API
+
** Python script on fixme.ch that serves the API
* Perl script that put the status in a Mysql DB (from the [[RFID_Doorlock]] or from a computer)
+
** Perl script that put the status in a Mysql DB (from the [[RFID_Doorlock]] or from a computer)
* A Drupal module to show the status on the main website
+
** A Drupal module to show the status on the main website
* MyHackerspace: Android pplication using SpaceAPI directory
+
* MyHackerspace: Android application using SpaceAPI directory
 
** [https://play.google.com/store/apps/details?id=ch.fixme.status Android Download on Play store]
 
** [https://play.google.com/store/apps/details?id=ch.fixme.status Android Download on Play store]
 
** [http://f-droid.org/repository/browse/?fdfilter=hackerspace&fdid=ch.fixme.status Download on F-Droid.org]
 
** [http://f-droid.org/repository/browse/?fdfilter=hackerspace&fdid=ch.fixme.status Download on F-Droid.org]

Revision as of 14:10, 7 September 2013

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