<commit_before>from flask import Flask, request
from GamePlay import GamePlay
import os
import sys
import json
import requests

app = Flask(__name__)
pyBot = GamePlay()

ACCESS_TOKEN = '<KEY>'
VERIFY_TOKEN = '<PASSWORD>'


@app.route('/webhook', methods=['GET'])
def handle_verification():
    if request.args.get("hub.verify_token") == VERIFY_TOKEN:
        return request.args.get("hub.challenge")
    else:
        return "Invalid verification token"


@app.route('/webhook', methods=['POST'])
def handle_incoming_message():
    data = request.json
    print(data)
    for event in data['entry']:
        messaging = event['messaging']
        for x in messaging:
            if x.get('message') and x['message'].get('text'):
                message = x['message']['text']
                recipient_id = x['sender']['id']

                print('server received msg: ' + message)

                return_msg = pyBot.processUserMessage(recipient_id, message)
                send_message(recipient_id, return_msg)
                print('server return msg: ' + return_msg)
            else:
                pass
    return "ok", 200


def send_message(recipient_id, message_text):

    log("sending message to {recipient}: {text}".format(recipient=recipient_id, text=message_text))

    params = {
        "access_token": ACCESS_TOKEN
    }
    headers = {
        "Content-Type": "application/json"
    }
    data = json.dumps({
        "recipient": {
            "id": recipient_id
        },
        "message": {
            "text": message_text
        }
    })
    r = requests.post("https://graph.facebook.com/v2.6/me/messages", params=params, headers=headers, data=data)
    if r.status_code != 200:
        log(r.status_code)<commit_msg>unicode string.<commit_after>from flask import Flask, request
from GamePlay import GamePlay
import os
import sys
import json
import requests
import unicodedata

app = Flask(__name__)
pyBot = GamePlay()

ACCESS_TOKEN = '<KEY>'
VERIFY_TOKEN = 'Danhth'


@app.route('/webhook', methods=['GET'])
def handle_verification():
    if request.args.get("hub.verify_token") == VERIFY_TOKEN:
        return request.args.get("hub.challenge")
    else:
        return "Invalid verification token"


@app.route('/webhook', methods=['POST'])
def handle_incoming_message():
    data = request.json
    print(data)
    for event in data['entry']:
        messaging = event['messaging']
        for x in messaging:
            if x.get('message') and x['message'].get('text'):
                message = x['message']['text']
                recipient_id = x['sender']['id']

                print('server received msg: ' + message)
                unicodedata.normalize('NFKD', message).encode('ascii', 'ignore')

                return_msg = pyBot.processUserMessage(recipient_id, message)
                send_message(recipient_id, return_msg)
                print('server return msg: ' + return_msg)
            else:
                pass
    return "ok", 200


def send_message(recipient_id, message_text):

    log("sending message to {recipient}: {text}".format(recipient=recipient_id, text=message_text))

    params = {
        "access_token": ACCESS_TOKEN
    }
    headers = {
        "Content-Type": "application/json"
    }
    data = json.dumps({
        "recipient": {
            "id": recipient_id
        },
        "message": {
            "text": message_text
        }
    })
    r = requests.post("https://graph.facebook.com/v2.6/me/messages", params=params, headers=headers, data=data)
    if r.status_code != 200:
        log(r.status_code)
{'fraction_non_alphanumeric': 0.13175487465181057, 'fraction_numerical': 0.004456824512534819, 'mean_word_length': 2.569582504970179, 'pattern_counts': {'":': 12, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '3537930', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1054, 'n_words': 233}