From ef88655bad20458b1d7c998300bf2ab55a9cca58 Mon Sep 17 00:00:00 2001 From: miles Date: Wed, 25 Mar 2026 02:38:06 +0400 Subject: [PATCH] added v1 of the project --- calculator.py | 36 ++++++++++++++++++++++++++++++++++++ server.js | 15 +++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 calculator.py create mode 100644 server.js diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000..6d2dcfc --- /dev/null +++ b/calculator.py @@ -0,0 +1,36 @@ +import requests +import sys + +def start_calculator(): + print("--- Welcome to the Calculator ---") + try: + num1 = float(input("Enter first number: ")) + op = input("Enter operator (+, -, *, /): ") + num2 = float(input("Enter second number: ")) + + if op == "+": print(f"Result: {num1 + num2}") + elif op == "-": print(f"Result: {num1 - num2}") + elif op == "*": print(f"Result: {num1 * num2}") + elif op == "/": print(f"Result: {num1 / num2}") + else: print("Invalid operator.") + except ValueError: + print("Please enter valid numbers.") + +def check_server(): + url = "http://localhost:6000/status" + try: + response = requests.get(url) + data = response.json() + + if data.get("run") == "yes": + print("Access granted by server.") + start_calculator() + else: + print("Access denied: The server said 'no'.") + sys.exit() + + except requests.exceptions.ConnectionError: + print("Error: Could not connect to the server. Is it running?") + +if __name__ == "__main__": + check_server() diff --git a/server.js b/server.js new file mode 100644 index 0000000..8459cad --- /dev/null +++ b/server.js @@ -0,0 +1,15 @@ +const express = require('express'); +const app = express(); +const PORT = 6000; + +// Change this variable to "no" to stop the Python script +let accessGranted = "no"; + +app.get('/status', (req, res) => { + res.json({ run: accessGranted }); +}); + +app.listen(PORT, () => { + console.log(`Server is running at http://localhost:${PORT}`); + console.log(`Current status: ${accessGranted}`); +});