add scripts to allow for minimal HTTP interface alongside traditional CLI

This commit is contained in:
dymik739 2023-05-30 22:32:11 +03:00
parent 6018537352
commit b18d13e922
6 changed files with 50 additions and 0 deletions

1
src/www/bitutils.py Symbolic link
View File

@ -0,0 +1 @@
../bitutils.py

1
src/www/divide.py Symbolic link
View File

@ -0,0 +1 @@
../divide.py

1
src/www/lib Symbolic link
View File

@ -0,0 +1 @@
../lib/

1
src/www/multiply.py Symbolic link
View File

@ -0,0 +1 @@
../multiply.py

23
src/www/web-divide.py Normal file
View File

@ -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!")

23
src/www/web-multiply.py Normal file
View File

@ -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!")