Skip to content

Commit

Permalink
🎨 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
UltiRequiem committed Jun 8, 2021
1 parent 1ffd661 commit 618192c
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 60 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[![image](https://user-images.githubusercontent.com/71897736/113590421-794cea80-95e7-11eb-8184-9aedad42131b.png)](https://flask-calculator.ultirequiem.repl.co)

# A Webapp Calculator made with Flask

<p>
<a href="https://github.com/UltiRequiem/flask-calculator/blob/main/LICENSE"><img alt="License: MIT" src="https://black.readthedocs.io/en/stable/_static/license.svg"></a>
<a href="https://github.com/UltiRequiem/
Expand All @@ -10,26 +12,36 @@ flask-calculator"><img alt="Code style: black" src="https://img.shields.io/tokei
A simple calculator made with Flask.

## Demo

Here is a working live demo: https://flask-calculator.ultirequiem.repl.co
It runs in [Repl.it](https://repl.it).

## Development setup

1. Clone the proyect

```bash
git clone https://github.com/UltiRequiem/flask-calculator.git ; cd flask-calculator
```

2. Create a virtual environment

```bash
python3 -m venv env;source env/bin/activate
```

3. Install the dependencies

```bash
pip install -r requirements
```

- All-in-one command

```
curl https://gist.githubusercontent.com/UltiRequiem/1c010d74971c417b92c82c959f53f275/raw/dfeef4d5b7829f4589afd70b87837b74b912e6da/srcipt.sh | bash
```

## License
[BSD 3-Clause License](./LICENSE)

[MIT](./LICENSE)
34 changes: 17 additions & 17 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@
from keep_alive import keep_alive, app


@app.route('/')
@app.route("/")
def main():
return render_template("calculator.html")


@app.route("/calculate", methods=['POST'])
@app.route("/calculate", methods=["POST"])
def calculate():
number_one = request.form['number_one']
number_two = request.form['number_two']
operation = request.form['operation']
number_one = request.form["number_one"]
number_two = request.form["number_two"]
operation = request.form["operation"]

if operation == 'add':
if operation == "add":
result = float(number_one) + float(number_two)
return render_template('calculator.html', result=result)
return render_template("calculator.html", result=result)

elif operation == 'subtract':
elif operation == "subtract":
result = float(number_one) - float(number_two)
return render_template('calculator.html', result=result)
return render_template("calculator.html", result=result)

elif operation == 'multiply':
elif operation == "multiply":
result = float(number_one) * float(number_two)
return render_template('calculator.html', result=result)
return render_template("calculator.html", result=result)

elif operation == 'divide':
elif operation == "divide":
result = float(number_one) / float(number_two)
return render_template('calculator.html', result=result)
return render_template("calculator.html", result=result)

else:
return render_template('calculator.html')
return render_template("calculator.html")


@app.errorhandler(404)
def not_found(error):
return render_template('404.html', error=error)
return render_template("404.html", error=error)


@app.errorhandler(500)
def server_error(error):
return render_template('500.html', error=error)
return render_template("500.html", error=error)


if __name__ == '__main__':
if __name__ == "__main__":
keep_alive()
13 changes: 13 additions & 0 deletions check_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from os import system

files = ["app.py", "keep_alive.py"]


def check_format():
for i in files:
system(f"pycodestyle --show-source --show-pep8 --format=default {i}")


if __name__ == "__main__":
check_format()
print("All done!")
13 changes: 13 additions & 0 deletions format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from os import system

files = ["app.py", "keep_alive.py"]


def format():
for i in files:
system(f"autopep8 --in-place --aggressive {i}")


if __name__ == "__main__":
format()
print("All done!")
8 changes: 5 additions & 3 deletions keep_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

app = Flask('')


def run():
app.run(host='0.0.0.0',port=random.randint(2000,9000))
app.run(host='0.0.0.0', port=random.randint(2000, 9000))


def keep_alive():
t = Thread(target=run)
t.start()
t = Thread(target=run)
t.start()
13 changes: 7 additions & 6 deletions static/main.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@import url('https://fonts.googleapis.com/css?family=Montserrat:400,600,700,900');
@import url("https://fonts.googleapis.com/css?family=Montserrat:400,600,700,900");
body {
width : 100%;
height : 750px;
width: 100%;
height: 750px;
display: flex;
flex-direction : column;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: 'Montserrat', sans-serif;
font-family: "Montserrat", sans-serif;
background-color: #ebedef;
padding: 0;
margin: 0;
}
}

61 changes: 28 additions & 33 deletions templates/calculator.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
<!DOCTYPE html>
<html>

<head>
<title>Flask Calculator</title>
<link rel="stylesheet" href={{url_for('static',filename='main.css')}}>
</head>

<body>
<section class="calculator">
<head>
<title>Flask Calculator</title>
<link rel="stylesheet" href={{url_for('static',filename='main.css')
}}>
</head>

<body>
<section class="calculator">
<h1>Flask Calculator App</h1>

<form action="/calculate" method="POST">

<label for="Number One">First Number</label>
<input type="number" placeholder="First Number" name="number_one"/>

<label for="Number Two">Second Number</label>
<input type="number" placeholder="Second Number" name="number_two"/>

<label for="Operation">Operation</label>
<select name="operation">
<option value="add">Add</option>
<option value="subtract">Subtract</option>
<option value="multiply">Multiply</option>
<option value="divide">Divide</option>
</select>


<input type="submit" value="Calculate" id="calc_btn" class="btn" />
<form action="/calculate" method="POST">
<label for="Number One">First Number</label>
<input type="number" placeholder="First Number" name="number_one" />

<h3>The result is: {{ result }}</h3>
<label for="Number Two">Second Number</label>
<input type="number" placeholder="Second Number" name="number_two" />

</form>
</section>
<label for="Operation">Operation</label>
<select name="operation">
<option value="add">Add</option>
<option value="subtract">Subtract</option>
<option value="multiply">Multiply</option>
<option value="divide">Divide</option>
</select>

<footer>
© 2021 <a href="https://github.com/UltiRequiem">Eliaz Bobadilla</a>
</footer>
<input type="submit" value="Calculate" id="calc_btn" class="btn" />

</body>
<h3>The result is: {{ result }}</h3>
</form>
</section>

<footer>
© 2021 <a href="https://github.com/UltiRequiem">Eliaz Bobadilla</a>
</footer>
</body>
</html>

0 comments on commit 618192c

Please sign in to comment.