<commit_before>#!/usr/bin/env python

import os
import random

from flask import (
	Flask,
	request,
	make_response,
	jsonify
)

app = Flask(__name__)
log = app.logger

global guess_word
guess_word = ['K', '_', '_', '_', '_', 'N']

def index_getter(letter):
	index = 0
	index_list =[]
	for i in list('kitten'.upper()):
		if i == letter:
			index_list.append(index)
		index+=1
	return index_list

@app.route('/webhook', methods=['POST'])
def webhook():
	req = request.get_json(silent=True, force=True)

	action = req['result']['action']
	res = {'test':'test'}

	if action == 'game.correct_guess' or action == 'game.wrong_guess':
		res = CheckLetter(req)
	elif action == 'game.correct.word':
		res = correctWord(req)
	else:
		log.error("Unexpeted action.")

	return make_response(jsonify(res))

def CheckLetter(req):

	letter = req['result']['resolvedQuery'].upper()
	letter_index = index_getter(letter)
	letter_diff = [i for i in list('kitten'.upper()) if i not in guess_word]

	if guess_word.count('_') > 0:
		if guess_word.count(letter) == 0 and letter in letter_diff:
			for i in letter_index:
				guess_word[i] = letter
			output = "That's right! " + ''.join(guess_word) + '. Guess the next one.'
		elif letter not in letter_diff:
			output = 'Almost there. Try again!'
		else:
			output = 'You named it already, try again. Word is ' + ''.join(guess_word)
	else:
		output = 'You are so smart! Fantastic! Here is your kitten.'

	return {
		"speech": output,
		"displayText": output,
		"contextOut": []
	}

def correctWord(req):
	output = 'You are so smart! Fantastic! Here is your kitten.'<commit_msg>last letter guess fix<commit_after>#!/usr/bin/env python

import os
import random

from flask import (
	Flask,
	request,
	make_response,
	jsonify
)

app = Flask(__name__)
log = app.logger

global guess_word
guess_word = ['K', '_', '_', '_', '_', 'N']

def index_getter(letter):
	index = 0
	index_list =[]
	for i in list('kitten'.upper()):
		if i == letter:
			index_list.append(index)
		index+=1
	return index_list

@app.route('/webhook', methods=['POST'])
def webhook():
	req = request.get_json(silent=True, force=True)

	action = req['result']['action']
	res = {'test':'test'}

	if action == 'game.correct_guess' or action == 'game.wrong_guess':
		res = CheckLetter(req)
	elif action == 'game.correct.word':
		res = correctWord(req)
	else:
		log.error("Unexpeted action.")

	return make_response(jsonify(res))

def CheckLetter(req):

	letter = req['result']['resolvedQuery'].upper()
	letter_index = index_getter(letter)
	letter_diff = [i for i in list('kitten'.upper()) if i not in guess_word]

	if guess_word.count('_') - 1 > 0:
		if guess_word.count(letter) == 0 and letter in letter_diff:
			for i in letter_index:
				guess_word[i] = letter
			output = "That's right! " + ''.join(guess_word) + '. Guess the next one.'
		elif letter not in letter_diff:
			output = 'Almost there. Try again!'
		else:
			output = 'You named it already, try again. Word is ' + ''.join(guess_word)
	else:
		output = 'You are so smart! Fantastic! Here is your kitten.'

	return {
		"speech": output,
		"displayText": output,
		"contextOut": []
	}

def correctWord(req):
	output = 'You are so smart! Fantastic! Here is your kitten.'
{'fraction_non_alphanumeric': 0.15320074580484774, 'fraction_numerical': 0.0027967681789931634, 'mean_word_length': 4.234146341463415, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1897942', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1137, 'n_words': 319}