cylindertransport-web.py

changeset 11
098335a1d510
child 14
ba3d8c56e6f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cylindertransport-web.py	Tue Apr 04 00:47:22 2017 +0200
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+import cgi, data, json, config
+from cylindertransport import CylinderSpacerCalculator
+
+# enable debugging
+import cgitb, sys
+sys.stderr = sys.stdout
+#cgitb.enable()
+
+
+def do_action(args):
+    if args["action"].value == "calculate":
+        cylinders = args.getlist("cylinders[]")
+        calc = CylinderSpacerCalculator(cylinders)
+        calc.calculate()
+        print json.dumps({
+            "objects": calc.circles,
+            "scale3d": config.SCALE3D
+            })
+    else:
+        print "unknown Action %s" % args["action"].value
+
+
+
+
+
+
+print("Content-Type: text/html;charset=utf-8")
+print("")
+
+args = cgi.FieldStorage()
+if "action" in args:
+    do_action(args)
+else:
+    # display the html content
+    content = open("stlviewer.html", "r").read()
+    cyls = ""
+    for cyl in sorted(data.CYLINDER.keys()):
+        cyls += "<li key=\"%s\" weight=\"%s\">%s</li>" % (
+            cyl, data.CYLINDER[cyl][3], data.CYLINDER[cyl][4]);
+    content = content.replace("<!-- PLACEHOLDER CYLINDERS -->", cyls)
+
+    print content

mercurial