mirror of
https://github.com/assenzostefano/class-website.git
synced 2025-02-26 20:07:37 +01:00
I moved some stuff around and fixed the api (I'm stupid)
This commit is contained in:
parent
acbce1bd1a
commit
f9b9de9a3d
73
api/app.py
73
api/app.py
@ -1,73 +0,0 @@
|
||||
from flask import Flask, render_template, request, redirect, session, url_for, jsonify
|
||||
from dotenv import load_dotenv
|
||||
import requests
|
||||
import os
|
||||
import urllib
|
||||
import pymongo
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
load_dotenv() #Load .env file
|
||||
PASSWORD_MONGODB = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
|
||||
URL_MONGODB = os.getenv('URL_MONGODB') #URL for MongoDB
|
||||
mongo_url = "mongodb+srv://elci:" + urllib.parse.quote_plus(PASSWORD_MONGODB) + URL_MONGODB #URL for MongoDB (with password)
|
||||
client = pymongo.MongoClient(mongo_url) #Connect to MongoDB
|
||||
database = client["website-class"] #Database name
|
||||
collection = database["school-time-table"]
|
||||
|
||||
@app.route('/', methods = ['GET', 'POST'])
|
||||
def api():
|
||||
if(request.method == 'GET'):
|
||||
collection_find_username = list(collection.find({}, {"School Subject": 1,}))
|
||||
array_username = collection_find_username[0]['School Subject']
|
||||
|
||||
|
||||
test = {
|
||||
"subject" : {
|
||||
"monday": {
|
||||
"Subject 1": array_username[0],
|
||||
"Subject 2": array_username[1],
|
||||
"Subject 3": array_username[2],
|
||||
"Subject 4": array_username[3],
|
||||
"Subject 5": array_username[4],
|
||||
"Subject 6": array_username[5],
|
||||
},
|
||||
"tuesday": {
|
||||
"Subject 1": array_username[6],
|
||||
"Subject 2": array_username[7],
|
||||
"Subject 3": array_username[8],
|
||||
"Subject 4": array_username[9],
|
||||
"Subject 5": array_username[10],
|
||||
"Subject 6": array_username[11],
|
||||
},
|
||||
"wednesday": {
|
||||
"Subject 1": array_username[12],
|
||||
"Subject 2": array_username[13],
|
||||
"Subject 3": array_username[14],
|
||||
"Subject 4": array_username[15],
|
||||
"Subject 5": array_username[16],
|
||||
"Subject 6": array_username[17],
|
||||
},
|
||||
"thursday": {
|
||||
"Subject 1": array_username[18],
|
||||
"Subject 2": array_username[19],
|
||||
"Subject 3": array_username[20],
|
||||
"Subject 4": array_username[21],
|
||||
"Subject 5": array_username[22],
|
||||
"Subject 6": array_username[23],
|
||||
},
|
||||
"friday": {
|
||||
"Subject 1": array_username[24],
|
||||
"Subject 2": array_username[25],
|
||||
"Subject 3": array_username[26],
|
||||
"Subject 4": array_username[27],
|
||||
"Subject 5": array_username[28],
|
||||
"Subject 6": array_username[29],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jsonify(test)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
@ -23,15 +23,17 @@ current_time = datetime.datetime.now()
|
||||
day = str(current_time.day)
|
||||
month = str(current_time.month)
|
||||
year = str(current_time.year)
|
||||
si = day + "-" + month + "-" + year
|
||||
hour = str(current_time.hour)
|
||||
minute = str(current_time.minute)
|
||||
second = str(current_time.second)
|
||||
long_date = day + "-" + month + "-" + year + " " + hour + ":" + minute + ":" + second
|
||||
mydict = {
|
||||
"Date": si,
|
||||
"Date": long_date,
|
||||
"School Subject": [],
|
||||
"Teacher": [],
|
||||
}
|
||||
x = collection.insert_one(mydict)
|
||||
|
||||
# row 4
|
||||
for row in range (1, 100):
|
||||
# column B ~ column F
|
||||
for column in range (1, 100):
|
||||
@ -42,7 +44,7 @@ for row in range (1, 100):
|
||||
for i in range(4,80):
|
||||
school_subject = ws.cell(row=i, column=column).value
|
||||
if school_subject == 0:
|
||||
find_document_username = list(collection.find({}, {"Date": si}))
|
||||
find_document_username = list(collection.find({}, {"Date": long_date}))
|
||||
array_username = find_document_username[0]["_id"]
|
||||
collection.update_one(
|
||||
{ "_id": ObjectId(array_username)},
|
||||
@ -51,7 +53,7 @@ for row in range (1, 100):
|
||||
})
|
||||
else:
|
||||
remove_things_in_front = school_subject.split(' ', 1)[1]
|
||||
find_document_username = list(collection.find({}, {"Date": si}))
|
||||
find_document_username = list(collection.find({}, {"Date": long_date}))
|
||||
array_username = find_document_username[0]["_id"]
|
||||
collection.update_one(
|
||||
{ "_id": ObjectId(array_username)},
|
||||
@ -66,7 +68,7 @@ for row in range (1, 100):
|
||||
if teacher == 0:
|
||||
pass
|
||||
else:
|
||||
find_document_username = list(collection.find({}, {"Date": si}))
|
||||
find_document_username = list(collection.find({}, {"Date": long_date}))
|
||||
array_username = find_document_username[0]["_id"]
|
||||
collection.update_one(
|
||||
{ "_id": ObjectId(array_username)},
|
||||
|
@ -1,16 +0,0 @@
|
||||
.orario {
|
||||
padding-top: 300px;
|
||||
text-align: center;
|
||||
}
|
||||
html, body {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
.background {
|
||||
position: absolute;
|
||||
display: block;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index:0;
|
||||
color: black;
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 2.3 MiB |
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
Binary file not shown.
Before Width: | Height: | Size: 45 KiB |
81
subdomains/api/app.py
Normal file
81
subdomains/api/app.py
Normal file
@ -0,0 +1,81 @@
|
||||
from flask import Flask, render_template, request, redirect, session, url_for, jsonify
|
||||
from dotenv import load_dotenv
|
||||
import requests
|
||||
import os
|
||||
import urllib
|
||||
import pymongo
|
||||
import datetime
|
||||
import requests
|
||||
import time
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
load_dotenv() #Load .env file
|
||||
PASSWORD_MONGODB = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
|
||||
URL_MONGODB = os.getenv('URL_MONGODB') #URL for MongoDB
|
||||
mongo_url = "mongodb+srv://elci:" + urllib.parse.quote_plus(PASSWORD_MONGODB) + URL_MONGODB #URL for MongoDB (with password)
|
||||
client = pymongo.MongoClient(mongo_url) #Connect to MongoDB
|
||||
database = client["website-class"] #Database name
|
||||
collection = database["school-time-table"]
|
||||
|
||||
@app.route('/', methods = ['GET', 'POST'])
|
||||
def api():
|
||||
current_time = datetime.datetime.now()
|
||||
day = str(current_time.day)
|
||||
month = str(current_time.month)
|
||||
year = str(current_time.year)
|
||||
hour = str(current_time.hour)
|
||||
minute = str(current_time.minute)
|
||||
long_date = day + "-" + month + "-" + year + hour + ":" + minute
|
||||
collection_find_username = list(collection.find({}, {"Date": long_date ,"School Subject": 1,}))
|
||||
array_username = collection_find_username[0]['School Subject']
|
||||
|
||||
test = {
|
||||
"subject" : {
|
||||
"monday": {
|
||||
"Subject 1": array_username[0],
|
||||
"Subject 2": array_username[1],
|
||||
"Subject 3": array_username[2],
|
||||
"Subject 4": array_username[3],
|
||||
"Subject 5": array_username[4],
|
||||
"Subject 6": array_username[5],
|
||||
},
|
||||
"tuesday": {
|
||||
"Subject 1": array_username[14],
|
||||
"Subject 2": array_username[15],
|
||||
"Subject 3": array_username[16],
|
||||
"Subject 4": array_username[17],
|
||||
"Subject 5": array_username[18],
|
||||
"Subject 6": array_username[19],
|
||||
},
|
||||
"wednesday": {
|
||||
"Subject 1": array_username[12],
|
||||
"Subject 2": array_username[13],
|
||||
"Subject 3": array_username[14],
|
||||
"Subject 4": array_username[15],
|
||||
"Subject 5": array_username[16],
|
||||
"Subject 6": array_username[17],
|
||||
},
|
||||
"thursday": {
|
||||
"Subject 1": array_username[28],
|
||||
"Subject 2": array_username[29],
|
||||
"Subject 3": array_username[30],
|
||||
"Subject 4": array_username[31],
|
||||
"Subject 5": array_username[32],
|
||||
"Subject 6": array_username[33],
|
||||
},
|
||||
"friday": {
|
||||
"Subject 1": array_username[42],
|
||||
"Subject 2": array_username[43],
|
||||
"Subject 3": array_username[44],
|
||||
"Subject 4": array_username[45],
|
||||
"Subject 5": array_username[46],
|
||||
"Subject 6": array_username[47],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jsonify(test)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Calendario</h1>
|
||||
</body>
|
||||
</html>
|
@ -1,13 +0,0 @@
|
||||
<!-- Hello world in HTML -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>My first HTML page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello world!</h1>
|
||||
{% for imageList in imageList %}
|
||||
<img src = "{{ url_for('static', filename=imageList)}}">
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
@ -4,19 +4,10 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>2 Elci - Homepage</title>
|
||||
<meta name="viewport" content="width=device-width" >
|
||||
<link rel="icon" type="image/png" href="static/images/assets/logo.png">
|
||||
<link rel="stylesheet" href="static/css/homepage.css" type="text/css"/>
|
||||
</head>
|
||||
<body>
|
||||
<canvas class="background"></canvas>
|
||||
<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>
|
||||
<script>
|
||||
particlesJS.load("particles-js", "{{ url_for('static', filename='particles.json') }}",
|
||||
function(){
|
||||
console.log("particles.json has loaded");
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Hello World!</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Orario</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user