<commit_before>import json

from flask import Flask
from flask import request
from flask import jsonify
from flask import render_template
from flask import send_from_directory

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from mappings.verb import Verb
from mappings.translation import Translation

from config import config

app = Flask(__name__)
app.debug = True

engine_config = (
    config['db_engine'],
    config['db_user'],
    config['db_password'],
    config['db_host'],
    config['db_name']
)

engine = create_engine('%s://%s:%s@%s/%s' % engine_config, echo=True)
Session = sessionmaker(bind=engine)
session = Session()

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/js/<path:path>')
def send_js(path):
    return send_from_directory('js', path)

@app.route('/conjugate', methods=['POST'])
def conjugate():
    lang = request.form['lang']
    verb = request.form['verb']

    for entry in session.query(Verb).filter_by(lang=lang, verb=verb):
        deserialized = json.JSONDecoder('latin-1').decode(entry.conjugations)
        return jsonify(conjugations=deserialized)

    return jsonify(conjugations={})

@app.route('/translate', methods=['GET'])
def translate():
    lang = request.args.get('lang')
    english = request.args.get('english')

    translations = []
    entries = session.query(Translation).filter_by(lang=lang, english=english)
    for entry in entries:
        translations.append({
            'lang': lang,
            'english': english,
            'verb': entry.verb,
            'description': entry.description
        })

    return jsonify(translations=translations)

if __name__ == '__main__':
    app.run()<commit_msg>Fixes utf-8 encoding bug in conjugations #12<commit_after>import json

from flask import Flask
from flask import request
from flask import jsonify
from flask import render_template
from flask import send_from_directory

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from mappings.verb import Verb
from mappings.translation import Translation

from config import config

app = Flask(__name__)
app.debug = True

engine_config = (
    config['db_engine'],
    config['db_user'],
    config['db_password'],
    config['db_host'],
    config['db_name']
)

engine = create_engine('%s://%s:%s@%s/%s?charset=utf8&use_unicode=0' % engine_config, echo=True)
Session = sessionmaker(bind=engine)
session = Session()

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/js/<path:path>')
def send_js(path):
    return send_from_directory('js', path)

@app.route('/conjugate', methods=['POST'])
def conjugate():
    lang = request.form['lang']
    verb = request.form['verb']

    for entry in session.query(Verb).filter_by(lang=lang, verb=verb):
        deserialized = json.JSONDecoder('utf-8').decode(entry.conjugations)
        return jsonify(conjugations=deserialized)

    return jsonify(conjugations={})

@app.route('/translate', methods=['GET'])
def translate():
    lang = request.args.get('lang')
    english = request.args.get('english')

    translations = []
    entries = session.query(Translation).filter_by(lang=lang, english=english)
    for entry in entries:
        translations.append({
            'lang': lang,
            'english': english,
            'verb': entry.verb,
            'description': entry.description
        })

    return jsonify(translations=translations)

if __name__ == '__main__':
    app.run()
{'fraction_non_alphanumeric': 0.13352272727272727, 'fraction_numerical': 0.0019886363636363634, 'mean_word_length': 4.102898550724638, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7338454', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1051, 'n_words': 247}