<commit_before>from flask import Flask, request, send_file, url_for, after_this_request
import os
import pypandoc
import io

from src.generate import generate

app = Flask(__name__)

available_settings = ['grammarTitle', 'grammarSubtitle', 'author', 'format',
                      'theme', 'csvColumnWord', 'csvColumnLocal',
                      'csvColumnDefinition', 'csvColumnPronunciation',
                      'csvColumnPartOfSpeech', 'layout']


@app.route('/', methods=['POST'])
def index():
    # Get all available string settings from posted object
    settings = {}
    for key in available_settings:
        settings[key] = request.form.get(key, None)

    print(settings)

    # Loop through the files posted to the endpoint, reading all
    # files as strings.
    markdown_file_strings = []
    lexicon_file_string = None
    for filename, blob in request.files.items():
        if filename.endswith('.csv'):
            lexicon_file_string = str(blob.read(), 'utf-8')
        else:
            markdown_file_strings.append(str(blob.read(), 'utf-8'))

    try:
        filename = generate(markdown_file_strings, lexicon_file_string,
                            settings)
        return filename
    except Exception as e:
        print(type(e).__name__)
        print(e)
        return 'ERROR' + str(e)


@app.route('/download')
def download():
    filename = request.args.get('filename')
    filepath = os.path.join('temp', filename)

    print('Received request with filename {0}'.format(filename))

    if filename.endswith('.html'):
        mimetype = 'text/html; charset=utf-8'
        attachment_filename = 'Grammar.html'
    elif filename.endswith('.pdf'):
        mimetype = 'application/pdf'
        attachment_filename = 'Grammar.pdf'
    else:
        return 'File not found', 404

    # Read the file into a BytesIO object, allowing it to be deleted before the
    # request is fulfilled.
    with open(filepath, 'rb') as f:
        file_object = io.BytesIO(f.read())
<commit_msg>Remove print statements<commit_after>from flask import Flask, request, send_file, url_for, after_this_request
import os
import pypandoc
import io

from src.generate import generate

app = Flask(__name__)

available_settings = ['grammarTitle', 'grammarSubtitle', 'author', 'format',
                      'theme', 'csvColumnWord', 'csvColumnLocal',
                      'csvColumnDefinition', 'csvColumnPronunciation',
                      'csvColumnPartOfSpeech', 'layout']


@app.route('/', methods=['POST'])
def index():
    # Get all available string settings from posted object
    settings = {}
    for key in available_settings:
        settings[key] = request.form.get(key, None)

    # Loop through the files posted to the endpoint, reading all
    # files as strings.
    markdown_file_strings = []
    lexicon_file_string = None
    for filename, blob in request.files.items():
        if filename.endswith('.csv'):
            lexicon_file_string = str(blob.read(), 'utf-8')
        else:
            markdown_file_strings.append(str(blob.read(), 'utf-8'))

    try:
        filename = generate(markdown_file_strings, lexicon_file_string,
                            settings)
        return filename
    except Exception as e:
        return 'ERROR' + str(e)


@app.route('/download')
def download():
    filename = request.args.get('filename')
    filepath = os.path.join('temp', filename)

    if filename.endswith('.html'):
        mimetype = 'text/html; charset=utf-8'
        attachment_filename = 'Grammar.html'
    elif filename.endswith('.pdf'):
        mimetype = 'application/pdf'
        attachment_filename = 'Grammar.pdf'
    else:
        return 'File not found', 404

    # Read the file into a BytesIO object, allowing it to be deleted before the
    # request is fulfilled.
    with open(filepath, 'rb') as f:
        file_object = io.BytesIO(f.read())

{'fraction_non_alphanumeric': 0.11248073959938366, 'fraction_numerical': 0.003338469440164355, 'mean_word_length': 2.75602700096432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1227304', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1091, 'n_words': 302}