def list_lists_get(): if request.method == 'GET': try: all_lists = lists.list_lists() except Exception as e: raise InvalidUsage(str(e)) return jsonify(all_lists) else: data = request.get_json() try: lists.import_lists(data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Lists imported'})
def list_timers_get(): if request.method == 'GET': try: all_timers = timers.list_timers() except Exception as e: logger.exception(e) raise InvalidUsage(str(e)) return jsonify(all_timers) else: data = request.get_json() try: timers.import_timers(data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Timers imported'})
def unlock_post(): if request.method == 'POST': try: lights.unlock() return jsonify({'message': 'lights unlocked'}) except Exception as e: raise InvalidUsage(str(e))
def hue_login_post(): data = request.get_json() login_data = {'code': data.get('code', None)} try: response = hue_auth.login(**login_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify(response)
def remove_timer_post(): data = request.get_json() timer_data = {'command': data.get('command', '')} try: timers.remove_timer(**timer_data) return jsonify({'message': 'Timer removed'}) except Exception as e: raise InvalidUsage(str(e))
def remove_alias_post(): data = request.get_json() alias_data = {'alias': data.get('alias', '')} try: aliases.remove_alias(**alias_data) return jsonify({'message': 'Alias removed'}) except Exception as e: raise InvalidUsage(str(e))
def add_timer_post(): data = request.get_json() timer_data = { 'command': data.get('command', ''), 'interval': data.get('interval', 30) } try: timers.add_timer(**timer_data) return jsonify({'message': 'Timer added'}) except Exception as e: raise InvalidUsage(str(e))
def remove_group_post(): if request.method == 'POST': data = request.get_json() remove_group_data = { 'group_name': data.get('group_name'), } try: group_name = alerts.remove_group(**remove_group_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Group removed: {}'.format(group_name)})
def remove_alert_post(): if request.method == 'POST': data = request.get_json() remove_alert_data = { 'name': data.get('name'), } try: alert_name = alerts.remove_alert(**remove_alert_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Alert removed: {}'.format(alert_name)})
def get_list(): if request.method == 'POST': data = request.get_json() list_data = { 'name': data.get('name', '') } try: list_dict = lists.get_list(**list_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify(list_dict)
def remove_list_post(): if request.method == 'POST': data = request.get_json() list_data = { 'name': data.get('name', '') } try: lists.remove_list(**list_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'List removed: {}'.format(list_data['name'])})
def change_lights_static_post(): if request.method == 'POST': data = request.get_json() lights_data = { 'color': data.get('color', '#FFFFFF'), 'brightness': data.get('brightness', None) } try: lights.change_lights_static(**lights_data) return jsonify({'message': 'changed lights'}) except Exception as e: raise InvalidUsage(str(e))
def list_groups_get(): if request.method == 'GET': sort = request.args.get('sort') page = request.args.get('page') limit = request.args.get('limit') search = request.args.get('search') try: list_groups, page_metadata = alerts.list_groups(sort=sort, page=page, limit=limit, search=search) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'groups': list_groups, 'page_metadata': page_metadata}) else: data = request.get_json() group_data = { 'groups': data.get('groups', None), } try: alerts.import_groups(**group_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Groups imported'})
def add_to_group_post(): if request.method == 'POST': data = request.get_json() add_to_group_data = { 'group_name': data.get('group_name'), 'alert_names': data.get('alert_names') } try: alert_names = alerts.add_to_group(**add_to_group_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Added to {}: {}'.format(data.get('group_name'), alert_names)})
def get_list_item_post(): if request.method == 'POST': data = request.get_json() list_data = { 'name': data.get('name', ''), 'index': data.get('index', None) } try: item, index = lists.get_list_item(**list_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'item': item, 'index': index})
def add_alias_post(): data = request.get_json() alias_data = { 'alias': data.get('alias', ''), 'command': data.get('command', ''), 'badge': data.get('badge', 'broadcaster') } try: aliases.add_alias(**alias_data) return jsonify({'message': 'Alias added'}) except Exception as e: raise InvalidUsage(str(e))
def remove_from_list_post(): if request.method == 'POST': data = request.get_json() list_data = { 'name': data.get('name', ''), 'index': data.get('index', 0) } try: lists.remove_from_list(**list_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Removed item from list (index {})'.format(list_data['index'])})
def add_to_list_post(): if request.method == 'POST': data = request.get_json() list_data = { 'name': data.get('name', ''), 'items': data.get('items', []) } try: lists.add_to_list(**list_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Added to list: {}'.format(list_data['items'])})
def remove_from_group_post(): if request.method == 'POST': data = request.get_json() remove_from_group_data = { 'group_name': data.get('group_name'), 'alert_names': data.get('alert_names') } try: alert_names = alerts.remove_from_group(**remove_from_group_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Removed from {}: {}'.format(data.get('group_name'), alert_names)})
def group_alert_post(): if request.method == 'POST': data = request.get_json() alert_data = { 'group_name': data.get('group_name', ''), 'random_choice': data.get('random', True) } try: alert_text = alerts.group_alert(**alert_data) if not alert_text: alert_text = 'Displayed alert' except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': alert_text})
def start_post(): if request.method == 'POST': data = request.get_json() twitchbot_data = { 'bot_name': data.get('bot_name', ''), 'client_id': data.get('client_id', ''), 'chat_token': data.get('chat_token', ''), 'channel': data.get('channel', ''), 'timeout': data.get('timeout', 15) } try: bot_id = twitchbot.setup_chatbot(**twitchbot_data) return jsonify({'message': 'started chatbot: {}'.format(bot_id)}) except Exception as e: raise InvalidUsage(str(e))
def change_lights_hue_post(): if request.method == 'POST': data = request.get_json() lights_data = { 'on': data.get('on', True), 'saturation': data.get('saturation', 0), 'brightness': data.get('brightness', 254), 'hue': data.get('hue', 0), 'effect': data.get('effect', 'none'), 'xy': data.get('xy', []) } try: lights.change_lights_hue(**lights_data) return jsonify({'message': 'changed lights'}) except Exception as e: raise InvalidUsage(str(e))
def add_alert_post(): if request.method == 'POST': data = request.get_json() add_alert_data = { 'name': data.get('name', ''), 'text': data.get('text', ''), 'sound': data.get('sound', ''), 'duration': data.get('duration', 3000), 'effect': data.get('effect', ''), 'image': data.get('image', ''), 'thumbnail': data.get('thumbnail', '') } try: alert_name = alerts.add_alert(**add_alert_data) except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': 'Alert in database: {}'.format(alert_name)})
def alert_post(): if request.method == 'POST': data = request.get_json() alert_data = { 'name': data.get('name', ''), 'text': data.get('text', ''), 'sound': data.get('sound', ''), 'duration': data.get('duration', 3000), 'effect': data.get('effect', ''), 'image': data.get('image', '') } try: alert_text = alerts.alert(**alert_data) if not alert_text: alert_text = 'Displayed alert' except Exception as e: raise InvalidUsage(str(e)) return jsonify({'message': alert_text})
def current_user_get(): try: response = twitch_auth.current_user() except Exception as e: raise InvalidUsage(str(e)) return jsonify(response)
def logout_post(): try: response = twitch_auth.logout() except Exception as e: raise InvalidUsage(str(e)) return jsonify(response)
def hue_logged_in_get(): try: response = {'logged_in': hue_auth.hue_logged_in()} except Exception as e: raise InvalidUsage(str(e)) return jsonify(response)