bunch of changes to free_rooms
This commit is contained in:
parent
be6fe442dd
commit
a5c891d155
|
@ -1,2 +1,3 @@
|
|||
/__pycache__
|
||||
/.env
|
||||
/.env
|
||||
/edt.png
|
|
@ -5,15 +5,34 @@
|
|||
<!--Import Google Icon Font-->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<!--Import materialize.css-->
|
||||
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
|
||||
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
|
||||
|
||||
<!--Let browser know website is optimized for mobile-->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- Navigation -->
|
||||
<nav>
|
||||
<div class="nav-wrapper">
|
||||
<a href="#" class="brand-logo">Staticky</a>
|
||||
<ul id="nav-mobile" class="right hide-on-med-and-down">
|
||||
<li><a href="#">Home</a></li>
|
||||
<li><a href="#">About</a></li>
|
||||
<li><a href="#">Contact</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="row">
|
||||
<!-- Header -->
|
||||
<header class="center-align">
|
||||
<h1>Welcome to Staticky</h1>
|
||||
<p>Your go-to solution for static websites</p>
|
||||
</header>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col s12 m6">
|
||||
<div class="card blue-grey darken-1">
|
||||
<div class="card-content white-text">
|
||||
|
@ -28,9 +47,34 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="page-footer">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col l6 s12">
|
||||
<h5 class="white-text">Staticky</h5>
|
||||
<p class="grey-text text-lighten-4">Your go-to solution for static websites.</p>
|
||||
</div>
|
||||
<div class="col l4 offset-l2 s12">
|
||||
<h5 class="white-text">Links</h5>
|
||||
<ul>
|
||||
<li><a class="grey-text text-lighten-3" href="#">Home</a></li>
|
||||
<li><a class="grey-text text-lighten-3" href="#">About</a></li>
|
||||
<li><a class="grey-text text-lighten-3" href="#">Contact</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-copyright">
|
||||
<div class="container">
|
||||
© 2023 Staticky
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!--JavaScript at end of body for optimized loading-->
|
||||
<script type="text/javascript" src="js/materialize.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
</html>
|
BIN
edt salles.xlsx
BIN
edt salles.xlsx
Binary file not shown.
12
main.py
12
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(
|
||||
|
|
|
@ -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 = []
|
||||
|
||||
|
|
Loading…
Reference in New Issue