Now send a screenshot of the timetable when you find Italian language in the school time table and I have fixed the school time table so no one has trouble reading it

This commit is contained in:
Stefano Assenzo 2023-01-28 15:28:50 +00:00 committed by GitHub
parent 14b7a724ae
commit 76af099702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 358 additions and 281 deletions

4
app.py
View File

@ -38,7 +38,9 @@ def orario():
response = Request(url, headers={"User-Agent": "Mozilla/5.0"}) response = Request(url, headers={"User-Agent": "Mozilla/5.0"})
webpage = urlopen(response).read() webpage = urlopen(response).read()
dict = list(json.loads(webpage)) dict = list(json.loads(webpage))
return render_template('orario/orario.html', data=dict) number = str(range(0,7))
day = str(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"])
return render_template('orario/orario.html', data=dict, number=number, day=day)
@app.route('/calendario') @app.route('/calendario')
def calendario(): def calendario():

View File

@ -1,14 +1,20 @@
from dotenv import load_dotenv from dotenv import load_dotenv
from bson.objectid import ObjectId from bson.objectid import ObjectId
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium import webdriver
from discord.ext import tasks, commands from discord.ext import tasks, commands
from discord.commands.context import ApplicationContext from discord.commands.context import ApplicationContext
from discord.commands import Option from discord.commands import Option
import discord import discord
import pymongo import pymongo
import urllib.parse import urllib.parse
from selenium import webdriver
import datetime import datetime
import os import os
import time
load_dotenv() # Load .env file load_dotenv() # Load .env file
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN') # Discord token DISCORD_TOKEN = os.getenv('DISCORD_TOKEN') # Discord token
@ -40,15 +46,32 @@ async def on_ready():
@tasks.loop(seconds=1) @tasks.loop(seconds=1)
async def orario(): async def orario():
documents = collection.find() documents = collection.find()
send_screenshot = 0
# Iterate through the documents # Iterate through the documents
for document in documents: for document in documents:
for day in document['School Subject']: for day in document['School Subject']:
for i, subject in enumerate(document['School Subject'][day]): for i, subject in enumerate(document['School Subject'][day]):
if subject['Subject'] == "CALF1 LINGUA ITALIANA": if subject['Subject'] == "CALF1 LINGUA ITALIANA":
# Send a message on channel #general with the subject found and the index of the subject # Send a message on channel #general with the subject found and the index of the subject
options = Options() # Set options
options.add_argument("--headless") # Headless mode (so you don't see the browser)
options.add_argument('--disable-gpu') # Disable GPU
if send_screenshot == 0:
driver = webdriver.Firefox(options=options)
driver.get('http://127.0.0.1:4999/orario')
time.sleep(5)
driver.get_screenshot_as_file("screenshot.png")
driver.quit()
await channel.send(file=discord.File('screenshot.png'))
os.remove("screenshot.png")
send_screenshot += 1
else:
pass
channel = bot.get_channel(1063753802638954519) channel = bot.get_channel(1063753802638954519)
await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']} at index: {i}") await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']} at index: {i}")
send_screenshot = 0
@bot.slash_command(name='change_school_time', description='Change school time') @bot.slash_command(name='change_school_time', description='Change school time')
async def change_school_time( async def change_school_time(

View File

@ -371,7 +371,6 @@ def update_time_school():
school_subject = ws.cell(row=i, column=column).value # Get school subject from excel file school_subject = ws.cell(row=i, column=column).value # Get school subject from excel file
teacher = ws.cell(row=i, column=column+1).value teacher = ws.cell(row=i, column=column+1).value
room = ws.cell(row=i, column=column+2).value room = ws.cell(row=i, column=column+2).value
print(school_subject)
if dont_repeat == 9: if dont_repeat == 9:
check_repeat += 1 check_repeat += 1
if check_repeat == 5: if check_repeat == 5:
@ -629,19 +628,21 @@ def update_time_school():
if school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE": if school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE":
for c in range(1,100): for c in range(1,100):
search_motoria = ws.cell(row=i, column=c).value search_motoria = ws.cell(row=i, column=c).value
#print(search_motoria)
if search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIE": if search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIE":
if c == column: if c == column:
print("Non valido") pass
print("Row " + str(i) + " Column " + str(c) + " is " + school_subject)
else: else:
search_class = ws.cell(row=3, column=c).value search_class = ws.cell(row=3, column=c).value
print(search_class)
print(gagaga_room)
collection.update_one( collection.update_one(
{ "_id": ObjectId(array_document_school_time_table)}, { "_id": ObjectId(array_document_school_time_table)},
{ "$set": { { "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_room)+ ".PE with": search_class, "School Subject." + array_test[0] + "." + str(gagaga_room-1)+ ".PE with": search_class,
} }
} }
) )
else: else:
print("") pass
update_time_school() update_time_school()

View File

@ -1,35 +1,54 @@
.styled-table {
.ExcelTable2007 {
border: 1px solid #B0CBEF;
border-width: 1px 0px 0px 1px;
font-size: 11pt;
font-family: Calibri;
font-weight: 100;
border-spacing: 0px;
border-collapse: collapse; border-collapse: collapse;
margin: 25px 0; font-family: 'Roboto Slab', serif;
font-size: 0.9em;
font-family: sans-serif;
min-width: 400px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
} }
.styled-table thead tr { .ExcelTable2007 TH {
background-color: #009879; background-image: url(excel-2007-header-bg.gif);
color: #ffffff; background-repeat: repeat-x;
text-align: left; font-weight: normal;
} font-size: 14px;
.styled-table th, border: 1px solid #9EB6CE;
.styled-table td { border-width: 0px 1px 1px 0px;
padding: 12px 15px; height: 17px;
font-family: 'Roboto Slab', serif;
} }
.styled-table tbody tr { .ExcelTable2007 TD {
border-bottom: 1px solid #dddddd;
border: 0px;
background-color: white;
padding: 10px 10px 10px 10px;
border: 1px solid #D0D7E5;
border-width: 0px 1px 1px 0px;
font-family: 'Roboto Slab', serif;
} }
.styled-table tbody tr:nth-of-type(even) { .ExcelTable2007 TD B {
background-color: #f3f3f3; border: 0px;
} background-color: white;
.styled-table tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}
.styled-table tbody tr.active-row {
font-weight: bold; font-weight: bold;
color: #009879; font-family: 'Roboto Slab', serif;
zoom: 50%;
}
.ExcelTable2007 TD.heading {
background-color: #E4ECF7;
text-align: center;
border: 1px solid #9EB6CE;
border-width: 0px 1px 1px 0px;
font-family: 'Roboto Slab', serif;
}
.ExcelTable2007 TH.heading {
background-image: url(excel-2007-header-left.gif);
background-repeat: none;
font-family: 'Roboto Slab', serif;
} }

View File

@ -1,14 +1,17 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% block styles %} {% block styles %}
<link rel="stylesheet" type="text/css" href="{{url_for('.static', filename='css/index.css')}}"> <link rel="stylesheet" type="text/css" href="{{url_for('.static', filename='css/index.css')}}">
{% endblock %} {% endblock %}
</head> </head>
<body> <body>
<table class="styled-table"> <table class="ExcelTable2007">
<tbody>
<tr> <tr>
<th></th>
<th scope="col">Lunedì</th> <th scope="col">Lunedì</th>
<th scope="col">Martedì</th> <th scope="col">Martedì</th>
<th scope="col">Mercoledì</th> <th scope="col">Mercoledì</th>
@ -17,6 +20,7 @@
<th scope="col">Sabato</th> <th scope="col">Sabato</th>
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">07:55</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][0]['Subject'] }}</td> <td>{{ i['School Subject']['Monday'][0]['Subject'] }}</td>
<td>{{ i['School Subject']['Tuesday'][0]['Subject'] }}</td> <td>{{ i['School Subject']['Tuesday'][0]['Subject'] }}</td>
@ -27,6 +31,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td></td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][0]['Teacher'] }}</td> <td>{{ i['School Subject']['Monday'][0]['Teacher'] }}</td>
<td>{{ i['School Subject']['Tuesday'][0]['Teacher'] }}</td> <td>{{ i['School Subject']['Tuesday'][0]['Teacher'] }}</td>
@ -37,6 +42,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">08:55</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][0]['Room'] }}</td> <td>{{ i['School Subject']['Monday'][0]['Room'] }}</td>
<td>{{ i['School Subject']['Tuesday'][0]['Room'] }}</td> <td>{{ i['School Subject']['Tuesday'][0]['Room'] }}</td>
@ -47,6 +53,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">08:55</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][1]['Subject'] }}</td> <td>{{ i['School Subject']['Monday'][1]['Subject'] }}</td>
<td>{{ i['School Subject']['Tuesday'][1]['Subject'] }}</td> <td>{{ i['School Subject']['Tuesday'][1]['Subject'] }}</td>
@ -57,6 +64,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td></td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][1]['Teacher'] }}</td> <td>{{ i['School Subject']['Monday'][1]['Teacher'] }}</td>
<td>{{ i['School Subject']['Tuesday'][1]['Teacher'] }}</td> <td>{{ i['School Subject']['Tuesday'][1]['Teacher'] }}</td>
@ -67,6 +75,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">09:55</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][1]['Room'] }}</td> <td>{{ i['School Subject']['Monday'][1]['Room'] }}</td>
<td>{{ i['School Subject']['Tuesday'][1]['Room'] }}</td> <td>{{ i['School Subject']['Tuesday'][1]['Room'] }}</td>
@ -77,6 +86,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">09:55</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][2]['Subject'] }}</td> <td>{{ i['School Subject']['Monday'][2]['Subject'] }}</td>
<td>{{ i['School Subject']['Tuesday'][2]['Subject'] }}</td> <td>{{ i['School Subject']['Tuesday'][2]['Subject'] }}</td>
@ -87,6 +97,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td></td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][2]['Teacher'] }}</td> <td>{{ i['School Subject']['Monday'][2]['Teacher'] }}</td>
<td>{{ i['School Subject']['Tuesday'][2]['Teacher'] }}</td> <td>{{ i['School Subject']['Tuesday'][2]['Teacher'] }}</td>
@ -97,6 +108,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">10:55</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][2]['Room'] }}</td> <td>{{ i['School Subject']['Monday'][2]['Room'] }}</td>
<td>{{ i['School Subject']['Tuesday'][2]['Room'] }}</td> <td>{{ i['School Subject']['Tuesday'][2]['Room'] }}</td>
@ -107,6 +119,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">11:10</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][3]['Subject'] }}</td> <td>{{ i['School Subject']['Monday'][3]['Subject'] }}</td>
<td>{{ i['School Subject']['Tuesday'][3]['Subject'] }}</td> <td>{{ i['School Subject']['Tuesday'][3]['Subject'] }}</td>
@ -117,6 +130,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td></td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][3]['Teacher'] }}</td> <td>{{ i['School Subject']['Monday'][3]['Teacher'] }}</td>
<td>{{ i['School Subject']['Tuesday'][3]['Teacher'] }}</td> <td>{{ i['School Subject']['Tuesday'][3]['Teacher'] }}</td>
@ -127,6 +141,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">12:10</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][3]['Room'] }}</td> <td>{{ i['School Subject']['Monday'][3]['Room'] }}</td>
<td>{{ i['School Subject']['Tuesday'][3]['Room'] }}</td> <td>{{ i['School Subject']['Tuesday'][3]['Room'] }}</td>
@ -137,6 +152,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">12:10</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][4]['Subject'] }}</td> <td>{{ i['School Subject']['Monday'][4]['Subject'] }}</td>
<td>{{ i['School Subject']['Tuesday'][4]['Subject'] }}</td> <td>{{ i['School Subject']['Tuesday'][4]['Subject'] }}</td>
@ -147,6 +163,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td></td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][4]['Teacher'] }}</td> <td>{{ i['School Subject']['Monday'][4]['Teacher'] }}</td>
<td>{{ i['School Subject']['Tuesday'][4]['Teacher'] }}</td> <td>{{ i['School Subject']['Tuesday'][4]['Teacher'] }}</td>
@ -157,6 +174,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">13:10</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][4]['Room'] }}</td> <td>{{ i['School Subject']['Monday'][4]['Room'] }}</td>
<td>{{ i['School Subject']['Tuesday'][4]['Room'] }}</td> <td>{{ i['School Subject']['Tuesday'][4]['Room'] }}</td>
@ -167,6 +185,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">13:10</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][5]['Subject'] }}</td> <td>{{ i['School Subject']['Monday'][5]['Subject'] }}</td>
<td>{{ i['School Subject']['Tuesday'][5]['Subject'] }}</td> <td>{{ i['School Subject']['Tuesday'][5]['Subject'] }}</td>
@ -177,6 +196,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td></td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][5]['Teacher'] }}</td> <td>{{ i['School Subject']['Monday'][5]['Teacher'] }}</td>
<td>{{ i['School Subject']['Tuesday'][5]['Teacher'] }}</td> <td>{{ i['School Subject']['Tuesday'][5]['Teacher'] }}</td>
@ -187,6 +207,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
<tr> <tr>
<td style="text-align: center; vertical-align: middle;">14:10</td>
{% for i in data %} {% for i in data %}
<td>{{ i['School Subject']['Monday'][5]['Room'] }}</td> <td>{{ i['School Subject']['Monday'][5]['Room'] }}</td>
<td>{{ i['School Subject']['Tuesday'][5]['Room'] }}</td> <td>{{ i['School Subject']['Tuesday'][5]['Room'] }}</td>
@ -256,5 +277,16 @@
<td>{{ i['School Subject']['Saturday'][7]['Room'] }}</td> <td>{{ i['School Subject']['Saturday'][7]['Room'] }}</td>
{% endfor %} {% endfor %}
</tr> </tr>
</tbody>
</table> </table>
<tr>
{% for i in data %}
{% for c in number %}
{% for b in day %}
<p>{{b + " " + c}}</p>
{% endfor %}
{% endfor %}
{% endfor %}
</tr>
</body> </body>