示例#1
0
def api_ampel():
	if request.method == 'GET':
		return jsonify(getStatus(AMPEL_FILE))

	elif request.method == 'POST':
		try:
			# convert lights to boolean
			red = isTrue(getParam('red'))
			yellow = isTrue(getParam('yellow'))
			green = isTrue(getParam('green'))
			mode = getParam('mode') if paramExists('mode') else 'custom'

			if mode == 'random':
				red, yellow, green = True, True, True

			status = { 'red': red, 'yellow': yellow, 'green': green, 'mode': mode }

			returnValue = setStatus(AMPEL_FILE, status)
			ampelEvent.set()
			ampelEvent.clear()
			return jsonify(returnValue)
		except TypeError:
			message = { 'success': False, 'status': 'Please provide boolean \
				values (true, 1, false, 0) for red, yellow and green.' }
			resp = jsonify(message)
			resp.status_code = 500
			return resp
示例#2
0
def api_muc():
	if request.method == 'GET':
		return jsonify(getStatus(MUC_FILE))
	elif request.method == 'POST':
		botOnline = isTrue(getParam('botOnline'))
		mucUsers = int(getParam('mucUsers'))
		status = { 'botOnline': botOnline, 'mucUsers': mucUsers }
		return jsonify(setStatus(MUC_FILE, status))
示例#3
0
def api_mateometer():
	if request.method == 'GET':
		return jsonify(getStatus(MATE_FILE))
	elif request.method == 'POST':
		try:
			bottles = int(getParam('bottles'))
			if bottles > 0 and bottles < 20:
				status = { 'bottles': bottles }
				returnValue = setStatus(MATE_FILE, status)
				return jsonify(returnValue)
			else:
				raise ValueError("Botte value not in allowed range (0-20).")
		except ValueError:
			message = { 'success': False, 'status': 'Please provide bottles attribute (0-20).' }
			resp = jsonify(message)
			resp.status_code = 500
			return resp
示例#4
0
def api_poll_ampel():
	flag = ampelEvent.wait(REQUEST_TIMEOUT)
	if not flag:
		return error504()
	return jsonify(getStatus(AMPEL_FILE))