<commit_before>from sanic import Sanic
from sanic.response import json
from pony.orm import db_session
from sanic_jwt import initialize, exceptions

from .settings import *
from .models import db, User, Note

db.bind(**DB_SETTINGS)
db.generate_mapping(create_tables=True)


async def authenticate(request):
    if not request.json:
        raise exceptions.AuthenticationFailed("Missing username or password.")

    username = request.json.get('username', None)
    password = request.json.get('password', None)

    if not username or not password:
        raise exceptions.AuthenticationFailed("Missing username or password.")

    with db_session:
        user = User.get(username=username)

    if user is None:
        raise exceptions.AuthenticationFailed("User not found.")

    if not user.compare_passwords(password):
        raise exceptions.AuthenticationFailed("Password is incorrect.")

    return user


app = Sanic()
initialize(app, authenticate)
app.config.update(APP_SETTINGS)

app.static('/static', './static/build/static/')
app.static('/html', './static/build/')


@app.route("/hooks/telegram/{}".format(TELEGRAM_SECRET_TOKEN), ["POST"])
async def telegram_hook(request):
    data = request.json
    message = data['message']
    username = message['from']['username']

    with db_session:
        user = User.get(username=username)
        if not user:
            user = User(username=username, password=message['text'][:20])

        Note(text=message['text'], user=user)

    return json({})
<commit_msg>jwt authwhatever<commit_after>from sanic import Sanic
from sanic.response import json
from pony.orm import db_session
from sanic_jwt import initialize, exceptions

from .settings import *
from .models import db, User, Note

db.bind(**DB_SETTINGS)
db.generate_mapping(create_tables=True)


async def authenticate(request):
    if not request.json:
        raise exceptions.AuthenticationFailed("Missing username or password.")

    username = request.json.get('username', None)
    password = request.json.get('password', None)

    if not username or not password:
        raise exceptions.AuthenticationFailed("Missing username or password.")

    with db_session:
        user = User.get(username=username)

    if user is None:
        raise exceptions.AuthenticationFailed("User not found.")

    if not user.compare_passwords(password):
        raise exceptions.AuthenticationFailed("Password is incorrect.")

    return user


app = Sanic()
initialize(app, authenticate)
app.config.update(APP_SETTINGS)

app.static('/static', './static/build/static/')
app.static('/html', './static/build/')


@app.route("/hooks/telegram/{}".format(TELEGRAM_SECRET_TOKEN), ["POST"])
async def telegram_hook(request):
    data = request.json
    message = data['message']
    username = message['from']['username']

    with db_session:
        user = User.get(username=username)
        if not user:
            password = <PASSWORD>.<PASSWORD>(message['text'][:20])
            user = User(username=username, password=password)

        Note(text=message['text'], user=user)

    return json({})

{'fraction_non_alphanumeric': 0.12138728323699421, 'fraction_numerical': 0.0012845215157353885, 'mean_word_length': 3.8824451410658307, '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': '2590455', 'n_tokens_mistral': 885, 'n_tokens_neox': 855, 'n_words': 225}