-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (34 loc) · 1.17 KB
/
app.py
File metadata and controls
42 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
from flask import Flask, request
from flask_cors import CORS
from acquire_spectra import (acquire_spectra, find_peaks)
app = Flask(__name__)
CORS(app)
try:
with open("version.txt","r") as f:
version = f.read()
app.config["VERSION"] = version
except:
print("no version file found")
@app.route("/", methods=["GET"])
def ftmw() -> str:
if "VERSION" not in app.config:
app.config["VERSION"] = "0.0.0"
return "<h1 style='color:blue'>Raston Lab FTMW API%s</h1>" % (" - Version "+app.config["VERSION"])
@app.route("/acquire_spectrum", methods=["POST"])
def acquire_spectrum() -> dict[bool, list[float], list[float]]:
# put incoming JSON into a dictionary
params = json.loads(request.data)
# convert dictionary values to strings and return as JSON
return acquire_spectra(params)
@app.route("/find_peaks", methods=["POST"])
def handle_peaks() -> dict[bool, dict[float, float], str]:
params = json.loads(request.data)
return find_peaks(
params["x"],
params["y"],
float(params["threshold"]),
)
# set debug to false in production environment
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5001)