diff --git a/src/www/bitutils.py b/src/www/bitutils.py new file mode 120000 index 0000000..c80f051 --- /dev/null +++ b/src/www/bitutils.py @@ -0,0 +1 @@ +../bitutils.py \ No newline at end of file diff --git a/src/www/divide.py b/src/www/divide.py new file mode 120000 index 0000000..9ae833a --- /dev/null +++ b/src/www/divide.py @@ -0,0 +1 @@ +../divide.py \ No newline at end of file diff --git a/src/www/lib b/src/www/lib new file mode 120000 index 0000000..5bf80bf --- /dev/null +++ b/src/www/lib @@ -0,0 +1 @@ +../lib/ \ No newline at end of file diff --git a/src/www/multiply.py b/src/www/multiply.py new file mode 120000 index 0000000..309bd8e --- /dev/null +++ b/src/www/multiply.py @@ -0,0 +1 @@ +../multiply.py \ No newline at end of file diff --git a/src/www/web-divide.py b/src/www/web-divide.py new file mode 100644 index 0000000..159f69b --- /dev/null +++ b/src/www/web-divide.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!") diff --git a/src/www/web-multiply.py b/src/www/web-multiply.py new file mode 100644 index 0000000..c140471 --- /dev/null +++ b/src/www/web-multiply.py @@ -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!")