Compare commits

...

7 Commits

Author SHA1 Message Date
Candlio 2b440ece91
Merge 5f2c313562 into 30696537a0 2024-12-16 19:37:07 +01:00
Marsisus 30696537a0
Merge pull request #2 from Ant020/main
Ajout de la durée de liberté des salles
2024-12-15 22:42:29 +01:00
Antonin 250ccebaf4 modified: parse_salles.py 2024-12-15 22:39:09 +01:00
Antnin 797514f712 ajout du temps de liberté des salles 2024-12-15 22:36:11 +01:00
Antnin 7b2ed855dc modified: .gitignore
modified:   parse_colles.py
	modified:   parse_salles.py
	new file:   requirements.txt
2024-12-15 22:28:30 +01:00
Candlio 5f2c313562
Add files via upload 2024-10-28 23:14:18 +01:00
Candlio ee1976e3f3
Add files via upload 2024-10-28 23:10:10 +01:00
6 changed files with 68 additions and 26 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/__pycache__ /__pycache__
/.env /.env
/edt.png /edt.png
/parseSallesTemp.py

View File

@ -5,6 +5,7 @@ from parse_colles import create_colloscope
from parse_salles import create_edt, parse_edt, create_image from parse_salles import create_edt, parse_edt, create_image
import os import os
from dotenv import load_dotenv, dotenv_values from dotenv import load_dotenv, dotenv_values
import random as rng
# Créer une instance du bot # Créer une instance du bot
@ -63,7 +64,11 @@ async def on_message(message):
return return
if "quoi" in message.content[-10:].lower(): if "quoi" in message.content[-10:].lower():
await message.channel.send(f"quoicoubeh {message.author.mention} !") r = rng.randint(0,1000)
if r == 1 :
await message.channel.send(f"quoicoubeh {message.author.mention} !")
else :
await message.channel.send(f"FEUUR {message.author.mention} !!!")
if "j'aime" in message.content.lower()[:6]: if "j'aime" in message.content.lower()[:6]:
await message.author.edit(nick=f"{message.content[6:]}") await message.author.edit(nick=f"{message.content[6:]}")

View File

@ -60,15 +60,15 @@ def create_colloscope(groupe:int, timezone:str = "Europe/Paris"):
day_number_sem = days_english.index(day_sem) day_number_sem = days_english.index(day_sem)
# Combine day_number_sem with date # Combine day_number_sem with date
new_days = day_number_sem + date.day; new_days = day_number_sem + date.day
if new_days > 30 and date.month in [4, 6, 9, 11]: if new_days > 30 and date.month in [4, 6, 9, 11]:
new_days = new_days - 30; new_days = new_days - 30
new_month = date.month + 1; new_month = date.month + 1
elif new_days > 31 and date.month in [1, 3, 5, 7, 8, 10, 12]: elif new_days > 31 and date.month in [1, 3, 5, 7, 8, 10, 12]:
new_days = new_days - 31; new_days = new_days - 31
new_month = date.month + 1; new_month = date.month + 1
else : else :
new_month = date.month; new_month = date.month
if (new_month <9): if (new_month <9):
combined_date = datetime(2025, new_month, new_days).date() combined_date = datetime(2025, new_month, new_days).date()
else: else:
@ -76,7 +76,7 @@ def create_colloscope(groupe:int, timezone:str = "Europe/Paris"):
if professor == None: if professor == None:
continue; continue
start_time = datetime.strptime(hour.split('-')[0][:-1], "%H").time() start_time = datetime.strptime(hour.split('-')[0][:-1], "%H").time()
@ -111,7 +111,7 @@ def create_colloscope(groupe:int, timezone:str = "Europe/Paris"):
time_ecart = offset""" time_ecart = offset"""
e.begin = start_datetime.astimezone(pytz.timezone(timezone)) e.begin = start_datetime.astimezone(pytz.timezone(timezone))
e.duration = ({'hours': 1}); e.duration = ({'hours': 1})
e.location = f"{room} - Saint-Louis" e.location = f"{room} - Saint-Louis"
e.description = f"Professeur: {professor}\nSalle: {room}\nMatière : {matière}" e.description = f"Professeur: {professor}\nSalle: {room}\nMatière : {matière}"
e.organizer = f"Groupe {groupe}" e.organizer = f"Groupe {groupe}"

View File

@ -4,7 +4,7 @@ import discord
from discord import app_commands, Embed from discord import app_commands, Embed
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
def create_edt(heure:int, semestre:int, day:int) -> list[int]: def create_edt(heure:int, semestre:int, day:str) -> list[(int, str, int)]:
days = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'] days = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
days_english = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] days_english = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
@ -18,19 +18,46 @@ def create_edt(heure:int, semestre:int, day:int) -> list[int]:
# Retrieve all coordinates where the cell value is 10 # Retrieve all coordinates where the cell value is 10
coordinates = [] coordinates = []
for cell in sheet[3 + (heure - 8) + 11*day_number_sem][1:]:
# initialize the coords of the cell
row = 3 + (heure - 8) + 11*day_number_sem
column = 0
for i, cell in enumerate(sheet[row][1:]):
column+=1
val = cell.value val = cell.value
if val is None or ("0" not in val and "O" not in val and "S1" not in val): if isEmptyRoom(val):
try: try:
freeTime = getFreeDuration(sheet, row, column, day_number_sem)
temp = sheet.cell(row=1, column=cell.column).value temp = sheet.cell(row=1, column=cell.column).value
if temp is not None: if temp is not None:
coordinates.append((temp, sheet.cell(row=2, column=cell.column).value)) coordinates.append((temp, sheet.cell(row=2, column=cell.column).value, freeTime))
except Exception as e: except Exception as e:
print(f"Error: {e}") print(f"Error: {e}")
return coordinates return coordinates
def isEmptyRoom(val:str) -> bool:
return (val is None or ("0" not in val and "O" not in val and "S1" not in val))
def isThisDay(row:int, dayNumber: int) -> bool :
return 3 + 11*dayNumber <= row <= 13 + 11*dayNumber
def getFreeDuration(sheet, row:int, column:int, dayNumber:int) -> int:
i = 0
val = sheet[row][column].value
while isEmptyRoom(val) and isThisDay(row, dayNumber):
i += 1
row += 1
val = sheet[row][column].value
if not isThisDay(row, dayNumber):
return i + 3
return i
def set_value(type, hour) -> str: def set_value(type, hour) -> str:
if type == "Amphi": if type == "Amphi":
return "🧪 Amphi" return "🧪 Amphi"
@ -46,9 +73,10 @@ def set_value(type, hour) -> str:
return "❓ Inconnu" return "❓ Inconnu"
else: else:
return "" return ""
def create_image(coordinates, hour, day): def create_image(coordinates, hour, day):
# Create a larger blank image with a custom background color # Create a larger blank image with a custom background color
img = Image.new('RGB', (800, 5000), color=(60, 63, 65)) img = Image.new('RGB', (1200, 5000), color=(60, 63, 65))
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
# Load a less formal and slightly larger font # Load a less formal and slightly larger font
@ -57,15 +85,15 @@ def create_image(coordinates, hour, day):
# Title # Title
title = f"EDT : {hour}h - {day}" title = f"EDT : {hour}h - {day}"
draw.text((400 - (draw.textbbox((0, 0), title, font=title_font)[2] - draw.textbbox((0, 0), title, font=title_font)[0]) // 2, 20), title, fill="white", font=title_font) draw.text((600 - (draw.textbbox((0, 0), title, font=title_font)[2] - draw.textbbox((0, 0), title, font=title_font)[0]) // 2, 20), title, fill="white", font=title_font)
# Description # Description
description = f"Liste des Salles disponibles à {hour}h" description = f"Liste des Salles disponibles à {hour}h"
draw.text((400 - (draw.textbbox((0, 0), description, font=font)[2] - draw.textbbox((0, 0), description, font=font)[0]) // 2, 80), description, fill="white", font=font) draw.text((600 - (draw.textbbox((0, 0), description, font=font)[2] - draw.textbbox((0, 0), description, font=font)[0]) // 2, 80), description, fill="white", font=font)
# Draw the table header with a different color # Draw the table header with a different color
header = ["Salle", "Type"] header = ["Salle", "Type", "Temps libre"]
x_text = [200, 600] x_text = [200, 600, 1000]
for i, h in enumerate(header): for i, h in enumerate(header):
draw.text((x_text[i] - (draw.textbbox((0, 0), h, font=font)[2] - draw.textbbox((0, 0), h, font=font)[0]) // 2, 140), h, fill="white", font=font) draw.text((x_text[i] - (draw.textbbox((0, 0), h, font=font)[2] - draw.textbbox((0, 0), h, font=font)[0]) // 2, 140), h, fill="white", font=font)
@ -86,13 +114,13 @@ def create_image(coordinates, hour, day):
y_text = 200 y_text = 200
line_height = 45 line_height = 45
padding = 8 padding = 8
for i, (room, room_type) in enumerate(coordinates): for i, (room, room_type, freeTime) in enumerate(coordinates):
if y_text + line_height + padding > 3000: if y_text + line_height + padding > 3000:
break break
fill_color = type_colors.get(room_type, (150, 150, 150)) fill_color = type_colors.get(room_type, (150, 150, 150))
# Draw rounded rectangle # Draw rounded rectangle
draw.rounded_rectangle([(0, y_text), (800, y_text + line_height)], radius=20, fill=fill_color) draw.rounded_rectangle([(0, y_text), (1200, y_text + line_height)], radius=20, fill=fill_color)
text_y = y_text + (line_height - font.getbbox(room)[3]) // 2 text_y = y_text + (line_height - font.getbbox(room)[3]) // 2
@ -102,10 +130,13 @@ def create_image(coordinates, hour, day):
# Draw the room type in darker gray # Draw the room type in darker gray
draw.text((600 - (draw.textbbox((0, 0), set_value(room_type, hour), font=font)[2] - draw.textbbox((0, 0), set_value(room_type, hour), font=font)[0]) // 2, text_y), set_value(room_type, hour), fill="gray", font=font) draw.text((600 - (draw.textbbox((0, 0), set_value(room_type, hour), font=font)[2] - draw.textbbox((0, 0), set_value(room_type, hour), font=font)[0]) // 2, text_y), set_value(room_type, hour), fill="gray", font=font)
# Draw the free time duration
draw.text((1000 - (draw.textbbox((0, 0), f"{freeTime}h", font=font)[2] - draw.textbbox((0, 0), f"{freeTime}h", font=font)[0]) // 2, text_y), f"{freeTime}h", fill="black", font=font)
y_text += line_height + padding y_text += line_height + padding
# Resize the image to fit the content # Resize the image to fit the content
img = img.crop((0, 0, 800, y_text)) img = img.crop((0, 0, 1200, y_text))
img.save("edt.png") img.save("edt.png")
@ -119,7 +150,7 @@ def parse_edt(coordinates, hour, day):
for i in range(min(25, len(coordinates))): for i in range(min(25, len(coordinates))):
embed1.add_field(name=f"**{coordinates[i][0]}**", inline=True, value=set_value(coordinates[i][1], hour)) embed1.add_field(name=f"**{coordinates[i][0]}**", inline=True, value=set_value(coordinates[i][1], hour))
embed1.set_footer(text="Made by Marsisus, Magos, Hugo, Gabriel... ") embed1.set_footer(text="Made by Marsisus, Magos, Hugo, Gabriel, Antonin... ")
embeds.append(embed1) embeds.append(embed1)
if len(coordinates) > 25: if len(coordinates) > 25:
@ -128,7 +159,7 @@ def parse_edt(coordinates, hour, day):
for i in range(25, len(coordinates)): for i in range(25, len(coordinates)):
embed2.add_field(name=f"**{coordinates[i][0]}**", value=set_value(coordinates[i][1], hour), inline=True) embed2.add_field(name=f"**{coordinates[i][0]}**", value=set_value(coordinates[i][1], hour), inline=True)
embed2.set_footer(text="Made by Marsisus, Magos, Hugo, Gabriel... ") embed2.set_footer(text="Made by Marsisus, Magos, Hugo, Gabriel, Antonin... ")
embeds.append(embed2) embeds.append(embed2)
return embeds return embeds

5
requirements.txt Normal file
View File

@ -0,0 +1,5 @@
discord
openpyxl
python-dotenv
ics
pytz

BIN
staticky-main.zip Normal file

Binary file not shown.