diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 87eeb67..615f90b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /__pycache__ -/.env \ No newline at end of file +/.env +/edt.png \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 2f8d90b..ac8a6e8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,15 +5,34 @@ - + + + -
+ +
+

Welcome to Staticky

+

Your go-to solution for static websites

+
+ + +
+
@@ -28,9 +47,34 @@
- +
+ + +
+
+
+
+
Staticky
+

Your go-to solution for static websites.

+
+
+
Links
+ +
+
+
+ +
+ - - \ No newline at end of file + \ No newline at end of file diff --git a/edt salles.xlsx b/edt salles.xlsx index 3e63fc6..f3b3f4b 100644 Binary files a/edt salles.xlsx and b/edt salles.xlsx differ diff --git a/font.ttf b/font.ttf new file mode 100644 index 0000000..ed9bd97 Binary files /dev/null and b/font.ttf differ diff --git a/main.py b/main.py index a5c563c..25f1f1e 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ from datetime import datetime import discord from discord import app_commands from parse_colles import create_colloscope -from parse_salles import create_edt, parse_edt +from parse_salles import create_edt, parse_edt, create_image import os from dotenv import load_dotenv, dotenv_values @@ -126,10 +126,12 @@ async def recup_edt( ): if 8 <= int(hour) <= 18: free_rooms = create_edt(int(hour), 1, day.capitalize()) - embeds = parse_edt(sorted(free_rooms), hour, day.capitalize()) - await interaction.response.send_message(embed=embeds[0]) - if len(embeds) == 2: - await interaction.followup.send(embed=embeds[1]) + # embeds = parse_edt(sorted(free_rooms), hour, day.capitalize()) + # await interaction.response.send_message(embed=embeds[0]) + # if len(embeds) == 2: + # await interaction.followup.send(embed=embeds[1]) + create_image(free_rooms, hour, day.capitalize()) + await interaction.response.send_message(file=discord.File("edt.png")) else: await interaction.response.send_message( diff --git a/parse_salles.py b/parse_salles.py index 63354ca..ff6c10f 100644 --- a/parse_salles.py +++ b/parse_salles.py @@ -2,6 +2,7 @@ import openpyxl from datetime import datetime, timedelta, timezone import discord from discord import app_commands, Embed +from PIL import Image, ImageDraw, ImageFont def create_edt(heure:int, semestre:int, day:int) -> list[int]: @@ -31,15 +32,83 @@ def create_edt(heure:int, semestre:int, day:int) -> list[int]: def set_value(type, hour) -> str: - if type == "sci": - return ":test_tube: :white_check_mark:" - if type == "info": - return ":desktop: :no_entry:" - if type == "colle": - return "<:colle:1309644102345949295> :grey_question:" - if type == "classe": - return ":mortar_board: :white_check_mark:" - else : return "" + if type == "Amphi": + return "๐Ÿงช Amphi" + if type == "TP": + return "๐Ÿ”ฌ TP" + if type == "Info": + return "๐Ÿ’ป Info" + if type == "Colle": + return "๐Ÿ“– Colle" + if type == "Classe": + return "๐ŸŽ“ Classe" + if type == "?": + return "โ“ Inconnu" + else: + return "" +def create_image(coordinates, hour, day): + # Create a larger blank image with a custom background color + img = Image.new('RGB', (800, 5000), color=(60, 63, 65)) + draw = ImageDraw.Draw(img) + + # Load a less formal and slightly larger font + font = ImageFont.truetype("font.ttf", 45) + title_font = ImageFont.truetype("font.ttf", 55) + + # Title + 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) + + # Description + 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 the table header with a different color + header = ["Salle", "Type"] + x_text = [200, 600] + 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) + + # Define background colors for each type of room + type_colors = { + "Amphi": (255, 153, 153), + "TP": (153, 204, 255), + "Info": (255, 204, 204), + "Colle": (255, 255, 153), + "Classe": (255, 229, 153), + "?": (224, 224, 224) + } + + # Sort coordinates by room type + coordinates.sort(key=lambda x: x[1]) + + # Draw the coordinates in a table format with alternating row colors + y_text = 200 + line_height = 50 + padding = 10 + for i, (room, room_type) in enumerate(coordinates): + if y_text + line_height + padding > 3000: + break + fill_color = type_colors.get(room_type, (150, 150, 150)) + + # Draw rounded rectangle + draw.rounded_rectangle([(0, y_text), (800, y_text + line_height)], radius=20, fill=fill_color) + + text_y = y_text + (line_height - font.getbbox(room)[3]) // 2 + + # Draw the room name + draw.text((200 - (draw.textbbox((0, 0), room, font=font)[2] - draw.textbbox((0, 0), room, font=font)[0]) // 2, text_y), room, fill="black", font=font) + + # 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) + + y_text += line_height + padding + + # Resize the image to fit the content + img = img.crop((0, 0, 800, y_text)) + + img.save("edt.png") + def parse_edt(coordinates, hour, day): embeds = []