From 88aed5bbb78fe7414a1dc43b91a880d62132df20 Mon Sep 17 00:00:00 2001 From: Mohammad Rameen Date: Thu, 11 Sep 2025 06:03:26 +0530 Subject: [PATCH] Added final coffee and wifi project --- .../day-62-coffee-and-wifi-end/cafe-data.csv | 6 ++ .../day-62-coffee-and-wifi-end/main.py | 69 +++++++++++++++++++ .../requirements.txt | 5 ++ .../static/css/styles.css | 24 +++++++ .../templates/add.html | 20 ++++++ .../templates/base.html | 25 +++++++ .../templates/cafes.html | 26 +++++++ .../templates/index.html | 23 +++++++ 8 files changed, 198 insertions(+) create mode 100644 Visual Studio Code Projects/day-62-coffee-and-wifi-end/cafe-data.csv create mode 100644 Visual Studio Code Projects/day-62-coffee-and-wifi-end/main.py create mode 100644 Visual Studio Code Projects/day-62-coffee-and-wifi-end/requirements.txt create mode 100644 Visual Studio Code Projects/day-62-coffee-and-wifi-end/static/css/styles.css create mode 100644 Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/add.html create mode 100644 Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/base.html create mode 100644 Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/cafes.html create mode 100644 Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/index.html diff --git a/Visual Studio Code Projects/day-62-coffee-and-wifi-end/cafe-data.csv b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/cafe-data.csv new file mode 100644 index 0000000..a291dec --- /dev/null +++ b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/cafe-data.csv @@ -0,0 +1,6 @@ +Cafe Name,Location,Open,Close,Coffee,Wifi,Power +Lighthaus,https://goo.gl/maps/2EvhB4oq4gyUXKXx9,11AM, 3:30PM,☕☕☕☕️,💪💪,🔌🔌🔌 +Esters,https://goo.gl/maps/13Tjc36HuPWLELaSA,8AM,3PM,☕☕☕☕,💪💪💪,🔌 +Ginger & White,https://goo.gl/maps/DqMx2g5LiAqv3pJQ9,7:30AM,5:30PM,☕☕☕,✘,🔌 +Mare Street Market,https://goo.gl/maps/ALR8iBiNN6tVfuAA8,8AM,1PM,☕☕,💪💪💪,🔌🔌🔌 +Test,https://hyper.is/,29pm,48am,☕☕☕,💪💪💪💪💪,🔌🔌🔌🔌🔌 \ No newline at end of file diff --git a/Visual Studio Code Projects/day-62-coffee-and-wifi-end/main.py b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/main.py new file mode 100644 index 0000000..fcc4d7b --- /dev/null +++ b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/main.py @@ -0,0 +1,69 @@ +from flask import Flask, render_template, redirect, url_for +from flask_bootstrap import Bootstrap5 +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField, SelectField +from wtforms.validators import DataRequired, URL +import csv + +''' +Red underlines? Install the required packages first: +Open the Terminal in PyCharm (bottom left). + +On Windows type: +python -m pip install -r requirements.txt + +On MacOS type: +pip3 install -r requirements.txt + +This will install the packages from requirements.txt for this project. +''' + +app = Flask(__name__) +app.config['SECRET_KEY'] = '8BYkEfBA6O6donzWlSihBXox7C0sKR6b' +Bootstrap5(app) + + +class CafeForm(FlaskForm): + cafe = StringField('Cafe name', validators=[DataRequired()]) + location = StringField("Cafe Location on Google Maps (URL)", validators=[DataRequired(), URL()]) + open = StringField("Opening Time e.g. 8AM", validators=[DataRequired()]) + close = StringField("Closing Time e.g. 5:30PM", validators=[DataRequired()]) + coffee_rating = SelectField("Coffee Rating", choices=["☕️", "☕☕", "☕☕☕", "☕☕☕☕", "☕☕☕☕☕"], validators=[DataRequired()]) + wifi_rating = SelectField("Wifi Strength Rating", choices=["✘", "💪", "💪💪", "💪💪💪", "💪💪💪💪", "💪💪💪💪💪"], validators=[DataRequired()]) + power_rating = SelectField("Power Socket Availability", choices=["✘", "🔌", "🔌🔌", "🔌🔌🔌", "🔌🔌🔌🔌", "🔌🔌🔌🔌🔌"], validators=[DataRequired()]) + submit = SubmitField('Submit') + + +@app.route("/") +def home(): + return render_template("index.html") + + +@app.route('/add', methods=["GET", "POST"]) +def add_cafe(): + form = CafeForm() + if form.validate_on_submit(): + with open("cafe-data.csv", mode="a", encoding='utf-8') as csv_file: + csv_file.write(f"\n{form.cafe.data}," + f"{form.location.data}," + f"{form.open.data}," + f"{form.close.data}," + f"{form.coffee_rating.data}," + f"{form.wifi_rating.data}," + f"{form.power_rating.data}") + return redirect(url_for('cafes')) + return render_template('add.html', form=form) + + +@app.route('/cafes') +def cafes(): + with open('cafe-data.csv', newline='', encoding='utf-8') as csv_file: + csv_data = csv.reader(csv_file, delimiter=',') + list_of_rows = [] + for row in csv_data: + list_of_rows.append(row) + return render_template('cafes.html', cafes=list_of_rows) + + +if __name__ == '__main__': + app.run(debug=True, port=5002) diff --git a/Visual Studio Code Projects/day-62-coffee-and-wifi-end/requirements.txt b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/requirements.txt new file mode 100644 index 0000000..1ea7856 --- /dev/null +++ b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/requirements.txt @@ -0,0 +1,5 @@ +Bootstrap_Flask==2.2.0 +Flask==2.3.2 +WTForms==3.0.1 +Flask_WTF==1.2.1 +Werkzeug=3.0.0 \ No newline at end of file diff --git a/Visual Studio Code Projects/day-62-coffee-and-wifi-end/static/css/styles.css b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/static/css/styles.css new file mode 100644 index 0000000..785baa8 --- /dev/null +++ b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/static/css/styles.css @@ -0,0 +1,24 @@ +/* to override Bootstrap styles for some things */ + +body { +background-color: #333; +color: white; +} + +a { + color: #ffc107; +} + +.jumbotron { + display: flex; + align-items: center; + margin: 0; + height: 100vh; + color: white; + background-color: #333; +} + +.space-above { + margin-top: 20px; + padding-top: 20px; +} diff --git a/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/add.html b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/add.html new file mode 100644 index 0000000..bf0df75 --- /dev/null +++ b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/add.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} +{% from 'bootstrap5/form.html' import render_form %} + +{% block title %}Add A New Cafe{% endblock %} +{% block content %} +
+
+
+

Add a new cafe into the database

+ + {{ render_form(form, novalidate=True) }} + +

+ See all cafes +

+
+
+
+ +{% endblock %} diff --git a/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/base.html b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/base.html new file mode 100644 index 0000000..f49a5d3 --- /dev/null +++ b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/base.html @@ -0,0 +1,25 @@ + + + + + + + {% block styles %} + + {{ bootstrap.load_css() }} + + + {% endblock %} + + {% block title %}{% endblock %} + + + {% block content %}{% endblock %} + + diff --git a/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/cafes.html b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/cafes.html new file mode 100644 index 0000000..6bc845b --- /dev/null +++ b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/cafes.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} +{% block title %}All Cafes{% endblock %} + +{% block content %} +
+
+
+

All Cafes

+ + + {% for row in cafes %} + + {% for item in row %} {% if item[0:4] == "http" %} + + {% else %} + + {% endif %} {% endfor %} + + {% endfor %} +
Maps Link{{ item }}
+

Return to index page

+
+
+
+ +{% endblock %} diff --git a/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/index.html b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/index.html new file mode 100644 index 0000000..31f8d6c --- /dev/null +++ b/Visual Studio Code Projects/day-62-coffee-and-wifi-end/templates/index.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} +{% block title %}Coffee and Wifi{% endblock %} + +{% block content %} +
+
+

☕️ Coffee & Wifi 💻

+

Want to work in a cafe but need power and wifi?

+
+

+ You've found the right place! Checkout my collection of cafes with data on + power socket availability, wifi speed and coffee quality. +

+ Show Me! +
+
+ +{% endblock %}