<commit_before>from flask import Flask, request
from command import cmd_repl, create_fifo, PIPENAME
import socket
import sys

app = Flask(__name__)
app.config['DEBUG'] = True


@app.route("/")
def hello():
    hostname = socket.gethostname()
    msg = """
    <html><head><title>Cheezoid</title></head>
    <body><h3>cheezoid httpd controller</h3>

    For example:<br>
    <ul>
    <li>
    Make current location the origin<br>
    <code>
    curl -X POST --data 'set' %s/cmd
    </code>
    </li>
    <li>
    Move cheezoid back to origin<br>
    <code>
    curl -X POST --data 'reset' %s/cmd
    </code>
    </li>
    <li>
    Move cheezoid back to origin then draw a line<br>
    <code>
    curl -X POST --data 'reset\\n pen down\\n move (13, 97)\\n pen up\\n' %s/cmd
    </code>
    </li>
    </ul>
    <br>
    Below are RESTful endpoints, POST to send, GET to receive<br>
    <ul>
    <li>/status to view cheezoid status</li>
    <li>/cmd to send command</li>
        <ul>
        <li>set: make current position origin. and orient cheezoid correctly</li>
        <li>move (relative angle in degree, relative distance in cm): orient cheezoid at angel of param 1 degrees to vertical Y
        then move distance in param 2 in cm </li>
        <li>pen [up/down]: put pen down or pen up </li>
        <li>reset: move cheezoid back to origin and oriented </li>
        </ul>
    <li>/svg to send svg</li>
    <li>/canvas to GUI</li>
    </ul>
    </body>
    </html>
"""
    return msg % (hostname, hostname, hostname)

@app.route("/cmd", methods=['POST', 'GET'])
def cmd_process():
    global fifo
    if request.method == 'GET':
        with open("static/cmd.html") as f:
            return f.read()
    elif request.method == 'POST':
        body = request.data or request.form.get("commands", request.form.keys()[0])
        cmds = cmd_repl(fifo, body)
        return "%s\n" % ("\n".join(cmds))

@app.route("/status")
def status_process():
    return "status\n"

@app.route("/svg")
def svg_process():
    return "svg\n"

@app.route("/canvas")
def canvas_process():
    return "canvas"

if __name__ == "__main__":
    global fifo
    fifo = create_fifo(PIPENAME)
    app.run(host="0.0.0.0", port=80)
    fifo.close()<commit_msg>links on the index page<commit_after>from flask import Flask, request
from command import cmd_repl, create_fifo, PIPENAME
import socket
import sys

app = Flask(__name__)
app.config['DEBUG'] = True


@app.route("/")
def hello():
    hostname = socket.gethostname()
    msg = """
    <html><head><title>Cheezoid</title></head>
    <body><h3>cheezoid httpd controller</h3>

    For example:<br>
    <ul>
    <li>
    Make current location the origin<br>
    <code>
    curl -X POST --data 'set' %s/cmd
    </code>
    </li>
    <li>
    Move cheezoid back to origin<br>
    <code>
    curl -X POST --data 'reset' %s/cmd
    </code>
    </li>
    <li>
    Move cheezoid back to origin then draw a line<br>
    <code>
    curl -X POST --data 'reset\\n pen down\\n move (13, 97)\\n pen up\\n' %s/cmd
    </code>
    </li>
    </ul>
    <br>
    Below are RESTful endpoints, POST to send, GET to receive<br>
    <ul>
    <li><a href="/status">/status<a> to view cheezoid status</li>
    <li><a href="/cmd">/cmd</a> to send command</li>
        <ul>
        <li>set: make current position origin. and orient cheezoid correctly</li>
        <li>move (relative angle in degree, relative distance in cm): orient cheezoid at angel of param 1 degrees to vertical Y
        then move distance in param 2 in cm </li>
        <li>pen [up/down]: put pen down or pen up </li>
        <li>reset: move cheezoid back to origin and oriented </li>
        </ul>
    <li><a href="/svg">/svg</a> to send svg</li>
    <li><a href="/canvas">/canvas</a> to GUI</li>
    </ul>
    </body>
    </html>
"""
    return msg % (hostname, hostname, hostname)

@app.route("/cmd", methods=['POST', 'GET'])
def cmd_process():
    global fifo
    if request.method == 'GET':
        with open("static/cmd.html") as f:
            return f.read()
    elif request.method == 'POST':
        body = request.data or request.form.get("commands", request.form.keys()[0])
        cmds = cmd_repl(fifo, body)
        return "%s\n" % ("\n".join(cmds))

@app.route("/status")
def status_process():
    return "I'm alive!"

@app.route("/svg")
def svg_process():
    return "Coming soon! ;)"

@app.route("/canvas")
def canvas_process():
    with open("static/cheezoid_canvas.html") as f:
        return f.read()

if __name__ == "__main__":
    global fifo
    fifo = create_fifo(PIPENAME)
    app.run(host="0.0.0.0", port=80)
    fifo.close()
{'fraction_non_alphanumeric': 0.15960207612456748, 'fraction_numerical': 0.006487889273356401, 'mean_word_length': 2.61328125, 'pattern_counts': {'":': 2, '<': 111, '<?xml version=': 0, '>': 111, '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': '6229454', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1608, 'n_words': 489}