aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorAnthony Wang2023-06-01 16:57:42 +0000
committerAnthony Wang2023-06-01 16:57:42 +0000
commit7c22096681a3e6d3c88cf34809fdbae5efd134a5 (patch)
tree2f9fe74eaa0186e4b962cfd02f6c156110cb9252 /main.py
parent03d6b663411d7ff2be42523540572bcef9f37820 (diff)
Make textgen script more genericHEADmaster
Diffstat (limited to 'main.py')
-rw-r--r--main.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..eaad486
--- /dev/null
+++ b/main.py
@@ -0,0 +1,35 @@
+import os
+import subprocess
+import sys
+import threading
+import time
+from flask import Flask, Response
+
+
+app = Flask(__name__)
+
+@app.route('/', defaults={'path': ''})
+@app.route('/<path:path>')
+def handler(path):
+ if path == 'favicon.ico':
+ return Response(status=204)
+
+ def run():
+ try:
+ proc = subprocess.Popen(
+ map(lambda x: x.replace('{PATH}', path), sys.argv[2:]),
+ stdout=subprocess.PIPE
+ )
+ for c in iter(lambda: proc.stdout.read(1), b''):
+ yield c
+ finally:
+ proc.kill()
+
+ return Response(run(), mimetype='text/plain')
+
+def fixperms():
+ time.sleep(0.05)
+ os.chmod(sys.argv[1], 660)
+
+threading.Thread(target=fixperms).start()
+app.run(host='unix://' + sys.argv[1])