<commit_before>#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# written by <NAME>

from flask import Flask, render_template, flash, redirect, request, url_for
from flask_bootstrap import Bootstrap
from flask_login import LoginManager, login_user, current_user, login_required, logout_user
from model import db, LogEntry, User, Sample
import json
from datetime import timedelta, date, datetime
import math
import time
import os
from flask_wtf import Form
from wtforms import TextField, PasswordField
from flask_bcrypt import Bcrypt
import old_xml_import
import sml_import
import dateutil.parser
import gzip

app = Flask('openmoves')

login_manager = LoginManager()
app_bcrypt = Bcrypt()


class LoginForm(Form):
    username = TextField()
    password = PasswordField()


def formatTime(time):
    return time.strftime("%Y-%m-%d %H:%M:%S %z")


def isoDate(date):
    return date.strftime("%Y-%m-%dT%H:%M:%S.%f%z")


def fromIsoDate(dateString):
    return datetime.strptime(dateString, "%Y-%m-%dT%H:%M:%S.%f%z")


def duration(value):
    if isinstance(value, str):
        value = timedelta(seconds=float(value))
    elif isinstance(value, float) or isinstance(value, int):
        value = timedelta(seconds=float(value))

    hours, remainder = divmod(value.total_seconds(), 3600)
    minutes, seconds = divmod(remainder, 60)
    return '%02d:%02d:%05.2f' % (hours, minutes, seconds)


def radianToDegree(value):
    return 180.0 / math.pi * value


def unixEpoch(date):
    return 1000 * time.mktime(date.timetuple())


def jsonify(value):
    if value:
        return json.dumps(value)


app.jinja_env.filters['jsonify'] = jsonify
app.jinja_env.filters['formatTime'] = formatTime
app.jinja_env.filters['isoDate'] = isoDate
app.jinja_env.filters['duration'] = duration
app.jinja_env.filters['degree'] = radianToDegree
app.jinja_env.filters['epoch'] = unixEpoch


def init(configFile='openmoves.cfg'):
    app.config.from_pyfile('openmoves.cfg.default', silent=True)
    app.config.from_pyfile(configFile, silent=True)

    if "SECRET_KEY" not in app.config or not app.config["SECRET_KEY"]:
        print("WARNING: no secret key configured. using a random secret key; please set SECRET_KEY in '%s'" % configFile)
        app.config["SECRET_KEY"] = os.urandom(32)

    db.init_app(app)

    Bootstrap(app)
    app_bcrypt.init_app(app)

    login_manager.init_app(app)
    login_manager.login_view = "login"
    return app


@login_manager.user_loader
def load_user(username):
    return User.query.filter_by(username=username).scalar()


@app.route('/import', methods=['GET', 'POST'])
@login_required
def moveImport():
    xmlfiles = request.files.getlist('files')
    importedMoves = []

    for xmlfile in xmlfiles:
        move = None
        filename = xmlfile.filename
        if filename.endswith('.gz'):
            xmlfile = gzip.GzipFile(fileobj=xmlfile, mode='rb', filename=filename)
            filename = filename[:-len('.gz')]
<commit_msg>improve warning message<commit_after>#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# written by <NAME>

from flask import Flask, render_template, flash, redirect, request, url_for
from flask_bootstrap import Bootstrap
from flask_login import LoginManager, login_user, current_user, login_required, logout_user
from model import db, LogEntry, User, Sample
import json
from datetime import timedelta, date, datetime
import math
import time
import os
from flask_wtf import Form
from wtforms import TextField, PasswordField
from flask_bcrypt import Bcrypt
import old_xml_import
import sml_import
import dateutil.parser
import gzip

app = Flask('openmoves')

login_manager = LoginManager()
app_bcrypt = Bcrypt()


class LoginForm(Form):
    username = TextField()
    password = PasswordField()


def formatTime(time):
    return time.strftime("%Y-%m-%d %H:%M:%S %z")


def isoDate(date):
    return date.strftime("%Y-%m-%dT%H:%M:%S.%f%z")


def fromIsoDate(dateString):
    return datetime.strptime(dateString, "%Y-%m-%dT%H:%M:%S.%f%z")


def duration(value):
    if isinstance(value, str):
        value = timedelta(seconds=float(value))
    elif isinstance(value, float) or isinstance(value, int):
        value = timedelta(seconds=float(value))

    hours, remainder = divmod(value.total_seconds(), 3600)
    minutes, seconds = divmod(remainder, 60)
    return '%02d:%02d:%05.2f' % (hours, minutes, seconds)


def radianToDegree(value):
    return 180.0 / math.pi * value


def unixEpoch(date):
    return 1000 * time.mktime(date.timetuple())


def jsonify(value):
    if value:
        return json.dumps(value)


app.jinja_env.filters['jsonify'] = jsonify
app.jinja_env.filters['formatTime'] = formatTime
app.jinja_env.filters['isoDate'] = isoDate
app.jinja_env.filters['duration'] = duration
app.jinja_env.filters['degree'] = radianToDegree
app.jinja_env.filters['epoch'] = unixEpoch


def init(configFile='openmoves.cfg'):
    app.config.from_pyfile('openmoves.cfg.default', silent=True)
    app.config.from_pyfile(configFile, silent=True)

    if "SECRET_KEY" not in app.config or not app.config["SECRET_KEY"]:
        print("WARNING: no secret key configured. Using a random secret key")
        print("Please run 'initialize_config.py' or set SECRET_KEY in '%s'" % configFile)
        app.config["SECRET_KEY"] = os.urandom(32)

    db.init_app(app)

    Bootstrap(app)
    app_bcrypt.init_app(app)

    login_manager.init_app(app)
    login_manager.login_view = "login"
    return app


@login_manager.user_loader
def load_user(username):
    return User.query.filter_by(username=username).scalar()


@app.route('/import', methods=['GET', 'POST'])
@login_required
def moveImport():
    xmlfiles = request.files.getlist('files')
    importedMoves = []

    for xmlfile in xmlfiles:
        move = None
        filename = xmlfile.filename
        if filename.endswith('.gz'):
            xmlfile = gzip.GzipFile(fileobj=xmlfile, mode='rb', filename=filename)
            filename = filename[:-len('.gz')]

{'fraction_non_alphanumeric': 0.12617135207496652, 'fraction_numerical': 0.008032128514056224, 'mean_word_length': 4.37983798379838, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '2386634', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1939, 'n_words': 455}