<commit_before># coding: utf8

from datetime import datetime

from flask import Flask, render_template, request, jsonify
from flask.ext.pymongo import PyMongo

app = Flask(__name__)
mongo = PyMongo(app)

EVENT_TIME_INTERVAL = 30  # seconds
ALIVE_INTERVAL = 3 * 60 # seconds


@app.route("/")
def index():
    #mongo.db.rooms.remove()
    return render_template("index.html")


@app.route("/rooms", methods=['GET', 'POST'])
def rooms():
    if request.method == 'POST':
        if not request.json or 'name' not in request.json:
            return 'You must send the room name: {"name": ...}', 400

        name = request.json['name']
        room = mongo.db.rooms.find_one({'_id': name})
        if room:
            return "Room %s already exists" % name, 409

        mongo.db.rooms.insert({'_id': name, 'events': [], 'heathchecked_at': None})
        return "", 201

    rooms = mongo.db.rooms.find() or []
    response = []
    for room in rooms:
        empty = False
        alive = room['heathchecked_at'] is not None and (datetime.now() - room['heathchecked_at'].replace(tzinfo=None)).seconds < ALIVE_INTERVAL

        response.append({
            'name': room['_id'],
            'empty': empty,
            'alive': alive,
        })

    return jsonify(rooms=list(response))


@app.route("/room/<name>", methods=['DELETE'])
def delete_room(name):
    mongo.db.rooms.remove({'_id': name})
    return "", 200


@app.route("/room/<name>/event", methods=['POST'])
def register_event(name):
    room = mongo.db.rooms.find_one({'_id': name})
    if room is None:
        return "", 404

    events = room.get('events', [])
    events.append(datetime.now())
    room = mongo.db.rooms.find_and_modify({'_id': name}, {'events': events[-10:]})
    return "",  201


@app.route("/healthcheck/<name>")
def heathcheck(name):
    room = mongo.db.rooms.find_one({'_id': name})
    if room is None:
        return "", 404

    room = mongo.db.rooms.find_and_modify({'_id': name}, {'heathchecked_at': datetime.now()})
    return "", 201


if __name__ == "__main__":
    app.debug = True
    app.run("0.0.0.0", 5000)

<commit_msg>Fix typo<commit_after># coding: utf8

from datetime import datetime

from flask import Flask, render_template, request, jsonify
from flask.ext.pymongo import PyMongo

app = Flask(__name__)
mongo = PyMongo(app)

EVENT_TIME_INTERVAL = 30  # seconds
ALIVE_INTERVAL = 3 * 60 # seconds


@app.route("/")
def index():
    #mongo.db.rooms.remove()
    return render_template("index.html")


@app.route("/rooms", methods=['GET', 'POST'])
def rooms():
    if request.method == 'POST':
        if not request.json or 'name' not in request.json:
            return 'You must send the room name: {"name": ...}', 400

        name = request.json['name']
        room = mongo.db.rooms.find_one({'_id': name})
        if room:
            return "Room %s already exists" % name, 409

        mongo.db.rooms.insert({'_id': name, 'events': [], 'healthchecked_at': None})
        return "", 201

    rooms = mongo.db.rooms.find() or []
    response = []
    for room in rooms:
        empty = False
        alive = room['healthchecked_at'] is not None and (datetime.now() - room['healthchecked_at'].replace(tzinfo=None)).seconds < ALIVE_INTERVAL

        response.append({
            'name': room['_id'],
            'empty': empty,
            'alive': alive,
        })

    return jsonify(rooms=list(response))


@app.route("/room/<name>", methods=['DELETE'])
def delete_room(name):
    mongo.db.rooms.remove({'_id': name})
    return "", 200


@app.route("/room/<name>/event", methods=['POST'])
def register_event(name):
    room = mongo.db.rooms.find_one({'_id': name})
    if room is None:
        return "", 404

    events = room.get('events', [])
    events.append(datetime.now())
    room = mongo.db.rooms.find_and_modify({'_id': name}, {'events': events[-10:]})
    return "",  201


@app.route("/healthcheck/<name>")
def healthcheck(name):
    room = mongo.db.rooms.find_one({'_id': name})
    if room is None:
        return "", 404

    room = mongo.db.rooms.find_and_modify({'_id': name}, {'healthchecked_at': datetime.now()})
    return "", 201


if __name__ == "__main__":
    app.debug = True
    app.run("0.0.0.0", 5000)


{'fraction_non_alphanumeric': 0.1709039548022599, 'fraction_numerical': 0.018832391713747645, 'mean_word_length': 2.9710280373831774, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5055299', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1384, 'n_words': 333}