From 462536043d22c7fd86b11384dac4d0d51d5cfaf1 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Tue, 30 May 2023 22:32:11 +0300 Subject: [PATCH] add scripts to allow for minimal HTTP interface alongside traditional CLI --- src/www/bitutils.py | 1 + src/www/divide.py | 1 + src/www/lib | 1 + src/www/multiply.py | 1 + src/www/web-divide.py | 23 +++++++++++++++++++++++ src/www/web-multiply.py | 23 +++++++++++++++++++++++ 6 files changed, 50 insertions(+) create mode 120000 src/www/bitutils.py create mode 120000 src/www/divide.py create mode 120000 src/www/lib create mode 120000 src/www/multiply.py create mode 100644 src/www/web-divide.py create mode 100644 src/www/web-multiply.py 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!")