From 828211d7e59d3c152cf167c7bc90cd5dcb942edd Mon Sep 17 00:00:00 2001
From: Kaister300 <109926616+Kaister300@users.noreply.github.com>
Date: Tue, 6 Feb 2024 23:01:05 +1100
Subject: [PATCH] Added Python Flask Server
- Added server.py in project folder to host site instead of using node
- Fixed bug in paragoncalc.js which stopped power being calculated
- Added Flask to requirements.txt
- Updated README to now include Python commands
---
README.md | 16 ++++++++++++++-
project/requirements.txt | 3 ++-
project/server.py | 28 ++++++++++++++++++++++++++
project/webpage/scripts/paragoncalc.js | 9 +++++----
4 files changed, 50 insertions(+), 6 deletions(-)
create mode 100644 project/server.py
diff --git a/README.md b/README.md
index 514a492..e65a41d 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ The webpage is being hosted through Cloudflare at the following address:
https://btd6paragoncalculator.pages.dev/
-## Getting Started
+## Getting Started - Node
Node.js will only be used to run the express server.
```bash
@@ -31,6 +31,20 @@ OR
node project/app.mjs
```
+## Getting Started - Python
+Use the `requirements.txt` in the `project` folder to download the necessary dependencies.
+
+```bash
+pip install -r project/requirements.txt
+```
+
+This project can also host a local server using the Flask package. Using the following command will start the server:
+
+```bash
+python3 project/server.py
+```
+
+## Building Site
Building the website requires Python3 and the `python-dotenv` package from pip. The build script can be run using:
```bash
py project/make.py
diff --git a/project/requirements.txt b/project/requirements.txt
index 3e338bf..87531d5 100644
--- a/project/requirements.txt
+++ b/project/requirements.txt
@@ -1 +1,2 @@
-python-dotenv
\ No newline at end of file
+python-dotenv
+flask
\ No newline at end of file
diff --git a/project/server.py b/project/server.py
new file mode 100644
index 0000000..bf1cf3b
--- /dev/null
+++ b/project/server.py
@@ -0,0 +1,28 @@
+"""
+Basic Flask server to serve webpage.
+"""
+
+from flask import Flask
+
+HOSTADDR = "localhost"
+PORT = 3124
+
+app = Flask(__name__, static_folder="webpage", static_url_path="")
+app.config.from_object(__name__)
+
+
+@app.route("/", methods=["GET"])
+def main_page():
+ """
+ Returns the main page of the application.
+
+ This function sends the static file "index.html" as the main page of the application.
+
+ Returns:
+ str: The content of the "index.html" file.
+ """
+ return app.send_static_file("index.html")
+
+
+if __name__ == "__main__":
+ app.run(host=HOSTADDR, port=PORT, debug=True)
diff --git a/project/webpage/scripts/paragoncalc.js b/project/webpage/scripts/paragoncalc.js
index c3eb726..658da49 100644
--- a/project/webpage/scripts/paragoncalc.js
+++ b/project/webpage/scripts/paragoncalc.js
@@ -274,10 +274,11 @@ class paragonCalc extends LitElement {
// Money Spent. Max is 60,000 power
if(!(this.paragoncost === 0)) {
let spentratio = this.paragoncost/20000
- this.power += Math.floor(form.moneyspent.value/spentratio);
- if(this.power > 60000) {
- this.power = 60000;
+ let costpower = Math.floor(form.moneyspent.value/spentratio);
+ if(costpower > 60000) {
+ costpower = 60000;
}
+ this.power += costpower;
}
// Pops or Income. Max is 90,000 power
@@ -386,7 +387,7 @@ class paragonCalc extends LitElement {
}
${this.paragoncost ?
html`NOTE: The cash injection is 3.15 times the base paragon cost. This would mean that the total cash injection allowed would be $${Math.round(3.15*this.paragoncost)}`
- : html`NOTE: Please chosse the Paragon and Difficulty first.`
+ : html`NOTE: Please choose the Paragon and Difficulty first.`
}
`;