Esempio n. 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
Esempio n. 2
0
def api_ledticker():
	"""
	if request.method == 'GET':
		text = request.args.get('text', '')
		ticker = ledticker.LedTicker()
		ticker.add_item(text)
		return ticker.get_output()

	if request.method == 'POST':
	"""

	text = getParam('text')
	lowPriority = isTrue(getParam('lowpriority')) if paramExists('lowpriority') else False

	ticker = ledticker.LedTicker(LEDTICKER_FILE)

	longAgo = False
	if lowPriority:
		mtime = stat(LEDTICKER_FILE).st_mtime
		longAgo = (datetime.datetime.fromtimestamp(mtime) + datetime.timedelta(seconds=30)) < datetime.datetime.now()

	if not lowPriority or (lowPriority and ticker.items_available() == 0 and longAgo):
		if not lowPriority:
			log.info("Received high priority message: %s" % text)
		ticker.add_item(text)
		ledtickerEvent.set()
		ledtickerEvent.clear()
	return jsonify({ 'success': True })
Esempio n. 3
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))