-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
58 lines (47 loc) · 1.25 KB
/
app.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import uvicorn
from svgkeyer import svg_display
from fastapi import FastAPI
from pydantic import BaseModel
from starlette.responses import FileResponse
app = FastAPI()
import threading, queue
def showforever(q: queue):
s = svg_display()
while True:
try:
work = q.get()
except:
print("Exception!!!")
continue
s.set_chroma(work['chromakey'])
s.show(work['fname'])
class showdata(BaseModel):
fname: str
chromakey: tuple
subs: list
@app.get("/")
async def root():
return {
"message": "Post data is required",
}
@app.post("/")
async def bugger(d: showdata):
fname = d.fname
chromakey=d.chromakey
subs = d.subs
print("subs: ",subs)
# Do template substitution
f = open(fname,'r')
data = f.read()
f.close()
for item in subs:
print("Replacing: ",item[0],item[1])
data=data.replace(item[0],item[1])
with open("tmp.svg",'w') as f:
f.write(data)
q.put({"fname": "tmp.svg", "chromakey": chromakey})
if __name__ == "__main__":
q = queue.Queue()
displaythread = threading.Thread(target=showforever, args=(q,), daemon=True)
displaythread.start()
uvicorn.run(app,host="0.0.0.0", port=8001)