def get(event, context): game_id = event['pathParameters']['id'] game = game_data.game_by_id(game_id) if game is None: return webutil.respond_not_found('a game with that id does not exist') return webutil.respond_success_json(dumps(game))
def get(event, context): slack_id = event['pathParameters']['id'] player = player_data.get_player(slack_id) if player is None: return webutil.respond_not_found('a player with that Slack id does not exist') return webutil.respond_success_json(json.dumps(player))
def handle(): characters = '' for character in character_data.all_characters(): character_string = '-' + character['name'] + '\n' characters += character_string slack_body = slackutil.ephemeral_response(characters) return webutil.respond_success_json(json.dumps(slack_body))
def handle(command_text): command_string_components = split_add_player_string(command_text) new_player_id = extract_slack_user_id(command_string_components) if player_exists(new_player_id): return webutil.respond_success('A player record for <@' + new_player_id + '> already exists.') index_of_new_player = determine_players_index() player_data.add_player_with_id(new_player_id, index_of_new_player) rank.increment_skill_matrix_size() slack_response = slackutil.in_channel_response('Alright, <@' + new_player_id + '> is ready to play!') return webutil.respond_success_json(json.dumps(slack_response))
def handle(command_text): command_text_components = re.split(r'[\"\"]', command_text) character_name = command_text_components[1] character_icon = re.sub(r'[<>\s]', '', command_text_components[2]) character = character_data.get_character_by_name(character_name) if character.count() > 0: return webutil.respond_success("A character with this name already exists") new_character = { 'name': character_name, 'image': character_icon } character_data.add_character(new_character) slack_body = slackutil.in_channel_response('Successfully added \"' + character_name + '\" as a character.') return webutil.respond_success_json(json.dumps(slack_body))
def handle(command_text): command_string_components = split_add_player_string(command_text) new_player_id = extract_slack_user_id(command_string_components) if player_exists(new_player_id): return webutil.respond_success('A player record for <@' + new_player_id + '> already exists.') index_of_new_player = determine_players_index() player_data.add_player_with_id(new_player_id, index_of_new_player) slack_response = slackutil.in_channel_response('Alright, <@' + new_player_id + '> is ready to play!') return webutil.respond_success_json(json.dumps(slack_response))
def handle(): # retrieve the rankings rankings = ranking.average_individual() # initialize the text table table = prettytable.PrettyTable(['Rank', 'Player', 'Character', 'Average']) # add each ranking entry to the table for index, player in enumerate(rankings): table.add_row([(index + 1), player['name'], player['character'], player['average']]) # covert the table to format that Slack will understand table_string = '```' + table.get_string(border=True) + '```' slack_response = slackutil.in_channel_response(table_string) return webutil.respond_success_json(json.dumps(slack_response))
def handle(): # retrieve the rankings rankings = rank.skill_rank() # initialize the text table table = prettytable.PrettyTable(['Rank', 'Player', 'Character', 'Skill']) # add each ranking entry to the table for index, player in enumerate(rankings): table.add_row([(index + 1), player['name'], player['character'], player['average']]) # covert the table to format that Slack will understand table_string = '```' + table.get_string(border=True) + '```' slack_response = slackutil.ephemeral_response(table_string) return webutil.respond_success_json(json.dumps(slack_response))
def testRespondSuccessJson(self): # Arrange body = {'array': [0, 1, 2], 'string': 'something'} expected_result = { 'statusCode': 200, 'headers': { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, 'body': json.dumps(body) } # Act result = webutil.respond_success_json(json.dumps(body)) # Assert self.assertDictEqual(expected_result, result)
def all(event, context): queryStringParameters = event.get('queryStringParameters') or {} size = int(queryStringParameters.get('size') or 25) page = int(queryStringParameters.get('page') or 0) player_id = queryStringParameters.get('player_id') if not player_id: any_player = '.*' games = game_data.games_for_player(any_player, size, page) else: games = game_data.games_for_player(player_id, size, page) response = { 'games': list(games), 'player_id': player_id, 'size': size, 'page': page } return webutil.respond_success_json(dumps(response))
def handle(command_text): command_text = trim_extra_whitespace(command_text) result_components = parse_results(command_text) race_count = parse_race_count(result_components[0]) scores = [] for i in range(1, len(result_components)): player_score = { 'player_id': re.sub('[<@]', '', result_components[i].split(' ')[1].split('|')[0]), 'score': int(result_components[i].split(' ')[2]), 'average': round(float(result_components[i].split(' ')[2]) / race_count, 2) } scores.append(player_score) game = { 'games': race_count, 'datetime': int(time.time()) * 1000, 'scores': scores } last_game = game_data.get_last_game() matrix_curr = last_game['skill_matrix'] matrix_updated = rank.update_rank_matrix_with_game(matrix_curr, game) game['skill_matrix'] = matrix_updated game_data.add_game(game) scores = sorted(scores, key=lambda k: k['average'], reverse=True) response_text = 'A game of *' + str(game.get('games')) + '* races was played! Average scores:' for score in scores: player_cursor = player_data.get_player(score['player_id']) or {} response_text += '\n' + player_cursor.get('name', '<Unknown>') response_text += ': ' + str(score['average']) response_text += '\n-------------------' response_text += '\nCheck out the updated rankings at http://kartskills.com!' slack_body = slackutil.in_channel_response(response_text) return webutil.respond_success_json(json.dumps(slack_body))
def all(event, context): all_characters = character_data.all_characters() response = {'characters': all_characters} return webutil.respond_success_json(dumps(response))
def average(event, context): ranking_average = { 'rankings': rank.average_individual() } return webutil.respond_success_json(json.dumps(ranking_average))
def skill(event, context): ranking_skill = { 'rankings': rank.skill_rank() } return webutil.respond_success_json(json.dumps(ranking_skill))
def all(event, context): all_characters = character_data.all_characters() response = { 'characters': all_characters } return webutil.respond_success_json(dumps(response))
def all(event, context): all_players = player_data.all_players() response = { 'players': list(all_players) } return webutil.respond_success_json(json.dumps(response))