diff --git a/json b/json new file mode 100644 index 0000000..afa72a7 --- /dev/null +++ b/json @@ -0,0 +1,36 @@ +{ + "space": "Krautspace", + "url": "https://www.krautspace.de/", + "issue_report_channels": "email", + "contact": { + "ml": "krautspace-announce@list.lstsrv.org", + "twitter": "@HackspaceJena", + "email": "office@hackspace-jena.de" + }, + "state": { + "lastchange": "0", + "open": "null", + "message": "open for public", + "icon": { + "open": "http://status.hackspace-jena.de/src/green.png", + "closed": "http://status.hackspace-jena.de/src/red.png" + } + }, + "api": "0.13", + "location": { + "lat": "50.9291968", + "lon": "11.5824294", + "address": "Krautgase 26, 07743 Jena, Germany" + }, + "logo": "https://media.krautspace.de/files/krautspace_v1.png", + "feeds": { + "wiki": { + "url": "https://www.krautspace.de/feed.php", + "type": "application/rss+xml" + }, + "calendar": { + "url": "https://grical.org/s/?query=%23krautspace&view=ical", + "type": "text/calendar" + } + } +} diff --git a/state.py b/state.py new file mode 100644 index 0000000..54f4c56 --- /dev/null +++ b/state.py @@ -0,0 +1,48 @@ +#!/usr/bin/python + +import urllib2 +import json +import time +import logging + +fileName = "json" +url = "http://status.hackspace-jena.de/status/button/" + +data = None +# Raum Status abrufen +try: + response = urllib2.urlopen(url, None, 8) +except: + logging.exception("urllib2") +else: + # Status lessen + data = response.read(1) + try: + data = int(data) + except: + logging.exception("ungueltigen Zustand gelesen") + data = None + +# JSON Vorlage einlesen +try: + fp = file(fileName) + raw = json.load(fp) + fp.close() +except: + logging.exception("file") + exit(1) + +# Bereich in dem der Status steht +state = raw["state"] +# letzte Verarbeitungszeit setzen +state["lastchange"] = str(int(time.time())) +# Status setzen +if data and data == 0: + state["open"] = "close" +elif data and data == 1: + state["open"] = "open" +else: + state["open"] = "null" + +# JSON Decodieren und ausgeben +print json.dumps(raw) diff --git a/state.sh b/state.sh new file mode 100755 index 0000000..86d1394 --- /dev/null +++ b/state.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Datei zum Zwischenspeichern +STATEFILE="./tmp/last_state" +# Zieldatei, welche aus dem Internet abrufbar ist +DESTINATION="./tmp/json_new" + +/usr/bin/python state.py > $STATEFILE +if [ $? -eq 0 ] # ohne Probleme JSON-Datei erstellt +then +# Veröffentliche JSON-Datei +/bin/cp $STATEFILE $DESTINATION +fi diff --git a/status.php b/status.php deleted file mode 100644 index f1c200c..0000000 --- a/status.php +++ /dev/null @@ -1,104 +0,0 @@ - - */ - -class hackSpaceStatusApiConfigAbstract -{ - public $leaseFilePath = 'dhcpd.leases'; -} - -/** - * Class for DHCP leases - */ -class dhcpLease -{ - private $_leaseFilePath; - - /** - * @param string $leaseFilePath - */ - public function __construct(string $leaseFilePath) - { - $this->_leaseFilePath = $leaseFilePath; - } - - /** - * Read the lease File - * @return string - */ - private function _readLeaseFile() - { - return file_get_contents($this->_leaseFilePath); - } - - /** - * Get Count of MAC-Adresses in the lease File - * @return int - */ - public function countLeases() - { - return preg_match_all('/(([0-9a-f]{2}:){5}[0-9a-f]{2})/i', $this->_readLeaseFile(), $match); - } -} - -/** - * HackSpace Status API Klasss - */ -class hackSpaceStatusApi -{ - private $_data; - - public function __construct() - { - $this->_data = $this->buildData(); - } - - /** - * Get Data to Transport over the API - * @return array - */ - public function buildData() - { - $data = array( - 'api' => '0.12', - 'space' => 'Hackspace-Jena', - 'icon' => array( - 'open' => '', - 'closed' => '' - ), - 'url' => 'http://www.hackspace-jena.de', - 'contact' => array( - // 'irc' => 'irc://hackint.org/hachspace-jena', - 'twitter' => 'http://twitter.com/HackspaceJena', - // 'email' => '', - 'ml' => 'hackspace-jena@uvena.de', - 'jabber' => 'hackspace@chat.lug-jena.de', - 'facebook' => 'http://facebook.com/HackspaceJena', - ), - 'lat' => 50.92867, - 'lon' => 11.585529 - ); - - $hackSpaceStatusApiConfigAbstractClass = new hackSpaceStatusApiConfigAbstract(); - $dhcpLeaseClass = new dhcpLease($hackSpaceStatusApiConfigAbstractClass->leaseFilePath); - $data['open'] = $dhcpLeaseClass->countLeases() > 0; - - return $data; - } - - /** - * Get Data as JSON - * @return string - */ - public function getJson() - { - return json_encode($this->_data); - } -} - -$hackSpaceStatusApiClass = new hackSpaceStatusApi(); -print $hackSpaceStatusApiClass->getJson();