add a flask server
This commit is contained in:
parent
e1a7632b40
commit
f672c6c706
3 changed files with 88 additions and 5 deletions
43
server.py
Executable file
43
server.py
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Run this stuff with `waitress-serve --port=5000 --call server:create_app`
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from flask import Flask, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/")
|
||||
def hello_world():
|
||||
return "Hello, World! Yoyoyo"
|
||||
|
||||
@app.route("/scan")
|
||||
def scan():
|
||||
command = ["bash", f"{os.getcwd()}/scanbuddy.bash", "scan"]
|
||||
|
||||
command += ["-d"] if (request.args.get("duplex", "n") == 'y') else []
|
||||
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
|
||||
output = result.stdout.strip()
|
||||
|
||||
print("Scanbuddy output: ")
|
||||
print(output)
|
||||
|
||||
return output
|
||||
# return f"Scanning {'duplex' if duplex == 'y' else ''}..."
|
||||
|
||||
@app.route("/dispatch")
|
||||
def dispatch():
|
||||
return "Dispatching..."
|
||||
|
||||
@app.route("/unscan")
|
||||
def unscan():
|
||||
return "Unscanning..."
|
||||
|
||||
def create_app():
|
||||
return app
|
||||
|
||||
if __name__=='__main__':
|
||||
from waitress import serve
|
||||
serve(app, host="0.0.0.0", port=8080)
|
||||
Loading…
Add table
Add a link
Reference in a new issue