Skip to content

Commit

Permalink
Added Python Flask Server
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Kaister300 committed Feb 6, 2024
1 parent d1552cf commit 828211d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion project/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python-dotenv
python-dotenv
flask
28 changes: 28 additions & 0 deletions project/server.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 5 additions & 4 deletions project/webpage/scripts/paragoncalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -386,7 +387,7 @@ class paragonCalc extends LitElement {
}
${this.paragoncost ?
html`<span class="warning"><strong>NOTE:</strong> 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)}</span>`
: html`<span class="warning"><strong>NOTE:</strong> Please chosse the Paragon and Difficulty first.</span>`
: html`<span class="warning"><strong>NOTE:</strong> Please choose the Paragon and Difficulty first.</span>`
}
</div>
`;
Expand Down

0 comments on commit 828211d

Please sign in to comment.