Difference between revisions of "SpaceAPI"

From Fixme.ch
Jump to: navigation, search
Line 12: Line 12:
 
* A Drupal module to show the status on the main website
 
* A Drupal module to show the status on the main website
  
 +
== Dummy script to lookup the status ==
 +
 +
<syntaxhighlight lang="python">
 +
#!/usr/bin/env python2
 +
import urllib
 +
try:
 +
import json
 +
except ImportError:
 +
import simplejson as json
 +
 +
URL = "https://fixme.ch/cgi-bin/spaceapi.py"
 +
try:
 +
con = urllib.urlopen(URL)
 +
hs_json = json.load(con)
 +
except IOError:
 +
print("An error occured sorry")
 +
exit(1)
 +
if hs_json['open']:
 +
print("OPENENENENEN")
 +
print("status is : %(status)s" %hs_json)
 +
print("the changes happens at %(lastchange)s" % hs_json)
 +
print("The duration is %(duration)s hours" % hs_json)
 +
else:
 +
print("The hackerspace is closed")
 +
<\syntaxhighlight>
 
== Participant ==
 
== Participant ==
 
* [[User:Nemen]]
 
* [[User:Nemen]]
 
* [[User:Gcmalloc]]
 
* [[User:Gcmalloc]]
 
* [[User:Rorist]]
 
* [[User:Rorist]]

Revision as of 17:52, 2 May 2012

Description

Components

  • Sources on Github
  • 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)
  • A Drupal module to show the status on the main website

Dummy script to lookup the status

#!/usr/bin/env python2
import urllib
try:
	import json
except ImportError:
	import simplejson as json
 
URL = "https://fixme.ch/cgi-bin/spaceapi.py"
try:
	con = urllib.urlopen(URL)
	hs_json = json.load(con)
except IOError:
	print("An error occured sorry")
	exit(1)
if hs_json['open']:
	print("OPENENENENEN")
	print("status is : %(status)s" %hs_json)
	print("the changes happens at %(lastchange)s" % hs_json)
	print("The duration is %(duration)s hours" % hs_json)
else:
	print("The hackerspace is closed")
<\syntaxhighlight>
== Participant ==
* [[User:Nemen]]
* [[User:Gcmalloc]]
* [[User:Rorist]]