added v1 of the project
This commit is contained in:
1 parent
f4ce5c5982
commit
ef88655bad
2 files changed
+51
No files matched your search
@@ -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()
|
||||
@@ -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}`);
|
||||
});
|
||||
Reference in new issue
Block a user