initial commit
This commit is contained in:
commit
2186c273dd
8
Readme.md
Normal file
8
Readme.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Project ????
|
||||
Build a (simple) webapp that will tell the user when he/she can go to church.
|
||||
|
||||
### Workflow:
|
||||
1. User enters website
|
||||
2. User enters group number for church
|
||||
3. User gets reponse where he/she can see at which services he/she is allowed
|
||||
|
29
app.py
Normal file
29
app.py
Normal file
@ -0,0 +1,29 @@
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
from services import Services
|
||||
app = Flask("Project Candle")
|
||||
services = Services()
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
|
||||
@app.route("/GetServices", methods=['GET', 'POST'])
|
||||
def GetServices():
|
||||
nummer = (request.json)["nummer"]
|
||||
if(nummer != None and nummer != ""):
|
||||
ser=services.GetServices(nummer)
|
||||
return jsonify(render_template("results.html", services=ser),)
|
||||
ser = services.GetAllServices()
|
||||
return render_template("results.html", services=ser)
|
||||
|
||||
def RunWeb():
|
||||
app.run(debug=True)
|
||||
|
||||
@app.route('/', methods=['POST'])
|
||||
def my_form_post():
|
||||
text = request.form['text']
|
||||
processed_text = text.upper()
|
||||
print(f'Inputted text is: {processed_text}')
|
||||
return processed_text
|
||||
|
||||
|
7
main.py
Normal file
7
main.py
Normal file
@ -0,0 +1,7 @@
|
||||
from app import *
|
||||
|
||||
def main():
|
||||
RunWeb()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
flask
|
||||
pandas
|
71
services.py
Normal file
71
services.py
Normal file
@ -0,0 +1,71 @@
|
||||
import datetime
|
||||
from sqlite3 import *
|
||||
import sqlite3
|
||||
import locale
|
||||
import random
|
||||
locale.setlocale(locale.LC_TIME, "nl_NL.utf-8") # swedish
|
||||
|
||||
class Services:
|
||||
def __init__(self, sqlpath="sqlite.db") -> None:
|
||||
self.sqlpath = sqlpath
|
||||
self.db = sqlite3.connect(self.sqlpath, check_same_thread=False)
|
||||
self.cursor = self.db.cursor()
|
||||
self.PopulateDB()
|
||||
|
||||
def GetAllServices(self):
|
||||
'''
|
||||
Get all services. Returns a dictionary with, for each key a tuple with (date, groups)
|
||||
'''
|
||||
serv = self.cursor.execute("select * from services").fetchall()
|
||||
res = {}
|
||||
for s in serv:
|
||||
date = datetime.datetime.strptime(s[1], "%Y-%m-%d %H:%M:%S")
|
||||
groups = s[2].split(":")
|
||||
res[s[0]] = (date, groups)
|
||||
return res
|
||||
|
||||
def GetServices(self, number):
|
||||
serv = self.GetAllServices()
|
||||
res = {}
|
||||
for i in serv:
|
||||
if(number in serv[i][1]):
|
||||
res[i] = serv[i]
|
||||
return res
|
||||
|
||||
def PopulateDB(self):
|
||||
'''
|
||||
Populate simple db
|
||||
'''
|
||||
query = f"""CREATE TABLE IF NOT EXISTS services
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
date STRING,
|
||||
groups STRING
|
||||
);
|
||||
"""
|
||||
self.cursor.execute(query)
|
||||
|
||||
def AddService(self, date, groups):
|
||||
query = f"""
|
||||
INSERT INTO services (date, groups)
|
||||
VALUES('{date}', '{groups}');
|
||||
"""
|
||||
self.cursor.execute(query)
|
||||
self.db.commit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
#fill db
|
||||
ser = Services()
|
||||
for i in range(100):
|
||||
d = datetime.datetime.now()
|
||||
d = d.replace(hour=random.randint(1, 23), day = random.randint(1, 28), month = random.randint(1, 12))
|
||||
d = d.strftime("%Y-%m-%d %H:%M:%S")
|
||||
g = ""
|
||||
for j in range(10):
|
||||
g += str(random.randint(1, 30))
|
||||
g += ":"
|
||||
ser.AddService(d, g)
|
||||
r = ser.GetAllServices()
|
||||
d = ser.GetServices(str(4))
|
||||
print(d)
|
||||
|
2
static/jquery-3.6.0.min.js
vendored
Normal file
2
static/jquery-3.6.0.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
22
static/script.js
Normal file
22
static/script.js
Normal file
@ -0,0 +1,22 @@
|
||||
function GetServices(){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/GetServices",
|
||||
data: JSON.stringify({
|
||||
"nummer": document.getElementById('nummer_input').value,
|
||||
}),
|
||||
contentType: "application/json",
|
||||
dataType: 'text json',
|
||||
success: function(response) {
|
||||
document.getElementById('resultblock').innerHTML = response
|
||||
},
|
||||
error: function(error){
|
||||
console.log(error);
|
||||
}
|
||||
// success: function(result) {
|
||||
// console.log("aa");
|
||||
// console.log(results);
|
||||
//
|
||||
// }
|
||||
});
|
||||
}
|
134
static/style.css
Normal file
134
static/style.css
Normal file
@ -0,0 +1,134 @@
|
||||
.headerblock{
|
||||
width: 100%;
|
||||
height: 5%;
|
||||
/* background-color: #FFFFFF; */
|
||||
}
|
||||
|
||||
/* --sonic-silver: #7a7978ff;
|
||||
--turquoise-green: #87cbacff;
|
||||
--aquamarine: #90ffdcff;
|
||||
--non-photo-blue: #8de4ffff;
|
||||
--aero: #8ac4ffff; */
|
||||
|
||||
|
||||
.bodyclass{
|
||||
background-color: #fffffc;
|
||||
}
|
||||
|
||||
.klanten_logo{
|
||||
padding: 1%;;
|
||||
}
|
||||
|
||||
.navbarbtn{
|
||||
float: right;
|
||||
font-size: 25px;
|
||||
padding: 2%;
|
||||
padding-left: 5%;
|
||||
padding-right: 5%;
|
||||
margin: 1%;;
|
||||
/* border: 1px solid black; */
|
||||
background-color: #fffffe;
|
||||
/* color: white; */
|
||||
}
|
||||
|
||||
.navbarbtn:hover{
|
||||
background-color: gray;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.requestblock{
|
||||
position: relative;
|
||||
/* border: 1px solid black; */
|
||||
left: 25%;
|
||||
padding: 5%;
|
||||
width: 40%;
|
||||
font-family: "Verdana";
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.resultblock{
|
||||
position: relative;
|
||||
background-color: #ffffff;
|
||||
/* border: 1px solid black; */
|
||||
left:25%;
|
||||
top: 50%;
|
||||
width: 40%;
|
||||
padding: 5%;
|
||||
font-family: "Verdana";
|
||||
}
|
||||
|
||||
.resultitem{
|
||||
padding: .5%;
|
||||
}
|
||||
|
||||
.klanten_logo:active{
|
||||
-webkit-animation:spin 4s linear infinite;
|
||||
-moz-animation:spin 4s linear infinite;
|
||||
animation:spin 4s linear infinite;
|
||||
}
|
||||
|
||||
@-moz-keyframes spin {
|
||||
100% { -moz-transform: rotate(360deg); }
|
||||
}
|
||||
@-webkit-keyframes spin {
|
||||
100% { -webkit-transform: rotate(360deg); }
|
||||
}
|
||||
@keyframes spin {
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
transform:rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.center {
|
||||
display: block;
|
||||
margin-left: 40%;
|
||||
margin-right: 60%;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.nummer_input{
|
||||
background-color:white;
|
||||
position: relative;
|
||||
padding: 2%;
|
||||
margin: 1%;
|
||||
width: 39.5%;
|
||||
left: 30%;
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
.nummer_button{
|
||||
position: relative;
|
||||
background-color: green;
|
||||
padding: 2%;
|
||||
margin: 1%;
|
||||
width: 40%;
|
||||
left: 30%;
|
||||
text-align: center;
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.nummer_button:hover{
|
||||
background-color: lightgreen;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.resultitem{
|
||||
margin: 1%;
|
||||
padding: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* .MainText{
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin-top: -100px;
|
||||
margin-left: -100px;
|
||||
font-family: "Verdana";
|
||||
} */
|
30
templates/base.html
Normal file
30
templates/base.html
Normal file
@ -0,0 +1,30 @@
|
||||
<!doctype html>
|
||||
<title>Rondzes</title>
|
||||
|
||||
<link rel="stylesheet" href="{{url_for('static', filename='style.css') }}">
|
||||
<script src="{{url_for('static', filename='jquery-3.6.0.min.js') }}"></script>
|
||||
<script src="{{url_for('static', filename='script.js') }}"></script>
|
||||
|
||||
|
||||
<body class="bodyclass">
|
||||
<header class="headerblock">
|
||||
<img class="klanten_logo" src="//image.protestantsekerk.net/uploads/klant484/logo.png" title="Rondzes" alt="logo">
|
||||
<div class="navbarbtn">
|
||||
<tr>
|
||||
Contact
|
||||
</tr>
|
||||
</div>
|
||||
<div class="navbarbtn">
|
||||
<tr>
|
||||
Aanmelden
|
||||
</tr>
|
||||
</div>
|
||||
<div class="navbarbtn">
|
||||
<tr>
|
||||
Wie zijn wij?
|
||||
</tr>
|
||||
</div>
|
||||
</header>
|
||||
<div id="content">{% block content %}{% endblock %}</div>
|
||||
</body>
|
||||
</html>
|
28
templates/index.html
Normal file
28
templates/index.html
Normal file
@ -0,0 +1,28 @@
|
||||
{% extends 'base.html' %}
|
||||
<head>
|
||||
<div class="headerblock">
|
||||
|
||||
</div>
|
||||
<h1>Mag ik naar de kapel?</h1>
|
||||
</head>
|
||||
|
||||
|
||||
{% block content %}
|
||||
<div class="requestblock">
|
||||
<div class="MainText">
|
||||
<h1 style="text-align: center;">Wanneer mag ik naar de kapel?</h1>
|
||||
<h3 style="text-align: center;">In welke groep bent u ingedeeld?</h3>
|
||||
</div>
|
||||
<input class="nummer_input" id="nummer_input" name="text" placeholder="Groep">
|
||||
<div class="nummer_button" onclick="GetServices()">Opvragen</div>
|
||||
<!-- <form method="POST">
|
||||
<input name="text">
|
||||
<input type="submit" value="Verzenden!">
|
||||
</form> -->
|
||||
</div>
|
||||
|
||||
<div class="resultblock" id="resultblock">
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
14
templates/results.html
Normal file
14
templates/results.html
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
{% for key, value in services.items() %}
|
||||
{% if(loop.index % 2 == 0) %}
|
||||
<div class="resultitem" style="background-color: lightcyan">
|
||||
Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}} uur.
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="resultitem" style="background-color: lightblue">
|
||||
Dienst op {{value[0].date().strftime("%A")}} on {{value[0].time().hour}} uur.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% endfor %}
|
13
templates/static/style.css
Normal file
13
templates/static/style.css
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
.center {
|
||||
display: block;
|
||||
margin-left: 40%;
|
||||
margin-right: 60%;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.nummer_button{
|
||||
width:5%;
|
||||
height: 3%;
|
||||
background-color: red;
|
||||
}
|
Loading…
Reference in New Issue
Block a user