<commit_before>from bottle import Bottle, request, response
import json
from redis import StrictRedis

PORT = 8089
app = Bottle()


@app.hook('after_request')
def enable_cors():
    """
    You need to add some headers to each request.
    Don't use the wildcard '*' for Access-Control-Allow-Origin in production.
    """
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Methods'] = 'PUT, GET, POST, DELETE, OPTIONS'
    response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'


@app.route('/', method=['OPTIONS', 'GET'])
def status():
    return "The API is running."


@app.route('/start', method=['OPTIONS', 'POST'])
def act():
    response.headers['Content-Type'] = 'application/json'
    if request.method != 'OPTIONS':
        StrictRedis().set("program", str(request.data))
    return {}


@app.route('/stop', method=['OPTIONS', 'POST'])
def act():
    response.headers['Content-Type'] = 'application/json'
    if request.method != 'OPTIONS':
        StrictRedis().delete("program")
    return {}


@app.route('/program', method=['OPTIONS', 'GET'])
def act():
    response.headers['Content-Type'] = 'application/json'
    if request.method == 'OPTIONS':
        return {}
    else:
        return json.loads(StrictRedis().get("program")) or {"1": "No program set."}


@app.route('/current', method=['OPTIONS', 'GET'])
def current():
    response.headers['Content-Type'] = 'application/json'
    if request.method == 'OPTIONS':
        return {}
    else:
        r = StrictRedis()
        current_temp = r.get("current_temp") or "n/a"
        current_setting = r.get("current_setting") or "off"
        minutes_left = r.get("minutes_left")
        minutes_left = "n/a" if minutes_left is None else minutes_left + " minute(s) left"
        print("ML %s" % minutes_left)
        data = {"setting": current_setting,
                "temp": str(current_temp) + " &deg;C",
                "minutes_left": minutes_left}
        return data


@app.route('/history', method=['OPTIONS', 'GET'])
def history():
    response.headers['Content-Type'] = 'application/json'
    if request.method == 'OPTIONS':
        return {}
    else:
        keys = StrictRedis().hkeys("history")
        res = {key: "http://localhost:%s/history/%s" % (PORT, key) for key in keys}
        print(res)
        return res


@app.route('/history/<item>', method=['OPTIONS', 'GET'])
def history_csv(item):
    response.headers['Content-Type'] = 'application/text'
    if request.method == 'OPTIONS':<commit_msg>more functionality<commit_after>from bottle import Bottle, request, response
import json
from redis import StrictRedis

PORT = 8089
app = Bottle()


@app.hook('after_request')
def enable_cors():
    """
    You need to add some headers to each request.
    Don't use the wildcard '*' for Access-Control-Allow-Origin in production.
    """
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Methods'] = 'PUT, GET, POST, DELETE, OPTIONS'
    response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'


@app.route('/', method=['OPTIONS', 'GET'])
def status():
    return "The API is running."


@app.route('/start', method=['OPTIONS', 'POST'])
def act():
    response.headers['Content-Type'] = 'application/json'
    if request.method != 'OPTIONS':
        StrictRedis().set("program", str(request.data))
    return {}


@app.route('/stop', method=['OPTIONS', 'POST'])
def act():
    response.headers['Content-Type'] = 'application/json'
    if request.method != 'OPTIONS':
        StrictRedis().delete("program")
    return {}


@app.route('/program', method=['OPTIONS', 'GET'])
def act():
    response.headers['Content-Type'] = 'application/json'
    if request.method == 'OPTIONS':
        return {}
    else:
        return json.loads(StrictRedis().get("program")) or {"1": "No program set."}


@app.route('/current', method=['OPTIONS', 'GET'])
def current():
    response.headers['Content-Type'] = 'application/json'
    if request.method == 'OPTIONS':
        return {}
    else:
        r = StrictRedis()
        current_temp = r.get("current_temp") or "n/a"
        current_setting = r.get("current_setting") or "off"
        minutes_left = r.get("minutes_left")
        minutes_left = "n/a" if minutes_left is None else minutes_left + " minute(s)"
        print("ML %s" % minutes_left)
        data = {"setting": current_setting,
                "temp": str(current_temp) + " &deg;C",
                "minutes_left": minutes_left}
        return data


@app.route('/history', method=['OPTIONS', 'GET'])
def history():
    response.headers['Content-Type'] = 'application/json'
    if request.method == 'OPTIONS':
        return {}
    else:
        keys = StrictRedis().hkeys("history")
        res = {key: "http://localhost:%s/history/%s" % (PORT, key) for key in keys}
        return res


@app.route('/history/<item>', method=['OPTIONS', 'GET'])
def history_csv(item):
    response.headers['Content-Type'] = 'application/text'
    if request.method == 'OPTIONS':
{'fraction_non_alphanumeric': 0.17520789015664281, 'fraction_numerical': 0.0019338619222587507, 'mean_word_length': 3.360876897133221, 'pattern_counts': {'":': 8, '<': 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': '6843062', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1593, 'n_words': 370}