Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull #77

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion day-14/simple-python-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN pip install -r requirements.txt
# Copy the application code into the container
COPY . .

# Expose the port the Flask application will be listening on
# Expose the port the Flask application will listening on
EXPOSE 5000

# Set environment variables, if necessary
Expand Down
36 changes: 31 additions & 5 deletions day-14/simple-python-app/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
from flask import Flask
from flask import Flask, render_template, request

app = Flask(__name__)

@app.route('/')
def hello():
return 'Hello, world!'
def home():
return render_template('index.html')

if __name__ == '__main__':
app.run()
@app.route('/calculate', methods=['POST'])
def calculate():
# Get grades and credits from form
grades = request.form.getlist('grade')
credits = request.form.getlist('credit')

# Convert grades to numerical values
grade_points = {
'A': 4.0,
'B': 3.0,
'C': 2.0,
'D': 1.0,
'F': 0.0
}

# Calculate total grade points and total credits
total_grade_points = sum(grade_points[grade] * float(credit) for grade, credit in zip(grades, credits))
total_credits = sum(float(credit) for credit in credits)

# Calculate GPA
if total_credits > 0:
gpa = total_grade_points / total_credits
else:
gpa = 0.0

return render_template('result.html', gpa=gpa)

if __name__ == '__main__':
app.run(debug=True)
2 changes: 1 addition & 1 deletion day-14/simple-python-app/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ phases:
- docker push "$DOCKER_REGISTRY_URL/$DOCKER_REGISTRY_USERNAME/simple-python-flask-app:latest"
post_build:
commands:
- echo "Build completed successfully!"
- echo "Build completed successfully!!"
artifacts:
files:
- '**/*'
Expand Down
18 changes: 18 additions & 0 deletions day-14/simple-python-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPA Calculator</title>
</head>
<body>
<h1>GPA Calculator</h1>
<form action="/calculate" method="post">
<label for="grades">Grades:</label>
<input type="text" name="grade" id="grade" placeholder="Grade" required>
<label for="credits">Credits:</label>
<input type="text" name="credit" id="credit" placeholder="Credit" required>
<button type="submit">Add Course</button>
</form>
</body>
</html>
13 changes: 13 additions & 0 deletions day-14/simple-python-app/results.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPA Result</title>
</head>
<body>
<h1>Your GPA</h1>
<p>Your GPA calculated is: {{ gpa }}</p>
<a href="/">Calculate again</a>
</body>
</html>
8 changes: 4 additions & 4 deletions day-14/simple-python-app/start_container.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -e

# Pull the Docker image from Docker Hub
echo
# Pull the Docker images from DockerHub
docker pull anushakirigere/simple-python-flask-app:latest

# Run the Docker image as a container
echo
# Run these Docker images as a container
docker run -d -p 5000:5000 anushakirigere/simple-python-flask-app:latest
5 changes: 3 additions & 2 deletions day-14/simple-python-app/stop_container.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -e

# Stop the running container (if any)
echo "Hi"
# Stop the running containers (if any)
contianerid = docker ps | awk -F "" '{print $1}'
docker rm -f $contianerid
4 changes: 2 additions & 2 deletions scripts/start_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

# Pull the Docker image from Docker Hub
docker pull abhishekf5/simple-python-flask-app
docker pull anushakirigere/simple-python-flask-app:latest

# Run the Docker image as a container
docker run -d -p 5000:5000 abhishekf5/simple-python-flask-app
docker run -d -p 5000:5000 anushakirigere/simple-python-flask-app:latest