add scripts to allow for minimal HTTP interface alongside traditional CLI
This commit is contained in:
parent
6018537352
commit
b18d13e922
|
@ -0,0 +1 @@
|
||||||
|
../bitutils.py
|
|
@ -0,0 +1 @@
|
||||||
|
../divide.py
|
|
@ -0,0 +1 @@
|
||||||
|
../lib/
|
|
@ -0,0 +1 @@
|
||||||
|
../multiply.py
|
|
@ -0,0 +1,23 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from divide import divide, table_to_text
|
||||||
|
|
||||||
|
print(os.environ, file = sys.stderr)
|
||||||
|
|
||||||
|
raw_params = list(map(lambda x: x.split("="), os.environ['QUERY_STRING'].split("&")))
|
||||||
|
baked_params = {k:v for (k, v) in raw_params}
|
||||||
|
bp = baked_params
|
||||||
|
|
||||||
|
if "x" in bp and "y" in bp and "m" in bp:
|
||||||
|
x = int("0b" + bp['x'], 2)
|
||||||
|
y = int("0b" + bp['y'], 2)
|
||||||
|
m = int(bp['m'])
|
||||||
|
dt, result = divide(max(list(map(len, [bp['x'], bp['y']]))), x, y, m)
|
||||||
|
|
||||||
|
print(f"Content-Type: text/plain; charset=UTF-8\r\n"
|
||||||
|
f"\r\n"
|
||||||
|
f"{table_to_text(dt)}\r\n"
|
||||||
|
f"Result: {result}")
|
||||||
|
else:
|
||||||
|
print("Content-Type: text/plain; charset=UTF-8\r\n\r\nCheck your input!")
|
|
@ -0,0 +1,23 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from multiply import multiply, table_to_text
|
||||||
|
|
||||||
|
print(os.environ, file = sys.stderr)
|
||||||
|
|
||||||
|
raw_params = list(map(lambda x: x.split("="), os.environ['QUERY_STRING'].split("&")))
|
||||||
|
baked_params = {k:v for (k, v) in raw_params}
|
||||||
|
bp = baked_params
|
||||||
|
|
||||||
|
if "x" in bp and "y" in bp and "m" in bp:
|
||||||
|
x = int("0b" + bp['x'], 2)
|
||||||
|
y = int("0b" + bp['y'], 2)
|
||||||
|
m = int(bp['m'])
|
||||||
|
dt, result = multiply(max(list(map(len, [bp['x'], bp['y']]))), x, y, m)
|
||||||
|
|
||||||
|
print(f"Content-Type: text/plain; charset=UTF-8\r\n"
|
||||||
|
f"\r\n"
|
||||||
|
f"{table_to_text(dt)}\r\n"
|
||||||
|
f"Result: {result}")
|
||||||
|
else:
|
||||||
|
print("Content-Type: text/plain; charset=UTF-8\r\n\r\nCheck your input!")
|
Loading…
Reference in New Issue