Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
danydudiot committed Sep 27, 2024

Verified

This commit was signed with the committer’s verified signature.
jjohannes Jendrik Johannes
2 parents 2ed195c + 49168d2 commit 1986c5a
Showing 5 changed files with 7,897 additions and 7,894 deletions.
6,945 changes: 3,465 additions & 3,480 deletions data/INGE.ics

Large diffs are not rendered by default.

8,789 changes: 4,394 additions & 4,395 deletions data/MIAGE.ics

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/Calendar.py
Original file line number Diff line number Diff line change
@@ -11,14 +11,14 @@

class Calendar:
"""Classe utilisée pour stocker une liste d'objet Event."""
def __init__(self, update : bool) -> None:
def __init__(self, update : bool, fleg_exam:list[str]) -> None:
""" Update : Si l'on doit télécharger les fichiers ics."""
# Dictionnaire qui stock les Event associé à l'UID.
self.events_dict : dict[str:Event]
self.events_list : list[Event]
self.exams_list : list[Event]

self.update_events(update)
self.update_events(update, fleg_exam)

def fetch_calendar(self, url:str, filename:str) -> None:
"""Télécharge le fichier .ics.
@@ -38,7 +38,7 @@ def convert_timestamp(self, input: str) -> datetime:
iso_date = f"{input[0:4]}-{input[4:6]}-{input[6:11]}:{input[11:13]}:{input[13:]}"
return datetime.fromisoformat(iso_date).astimezone(timezone("Europe/Paris"))

def update_events(self, update: bool) -> None:
def update_events(self, update: bool, flag_exam : list[str]) -> None:
"""Met à jour la liste d'événements en mêlant les événements issus des deux .ics.
Update : Si l'on doit télécharger les fichiers ics.
"""
@@ -55,14 +55,14 @@ def update_events(self, update: bool) -> None:

self.exam_list = []
# | sert à concaténer deux dictionnaires.
output = self.parse_calendar(filenameINGE) | self.parse_calendar(filenameMIAGE)
output = self.parse_calendar(filenameINGE, flag_exam) | self.parse_calendar(filenameMIAGE, flag_exam)


self.events_dict = output
# Tri les événements par ordre croissant en fonction de leur date.
self.events_list = sorted(list(self.events_dict.values()),key=lambda event: event.start_timestamp)

def parse_calendar(self, filename:str) -> dict[str:Event]:
def parse_calendar(self, filename:str, flag_exam:list[str]) -> dict[str:Event]:
"""Extrait les données du fichier .ics passé dans filename.
Filename : Chemin du fichier."""
# On lit tout le fichiers ICS
@@ -86,7 +86,8 @@ def parse_calendar(self, filename:str) -> dict[str:Event]:
event["SUMMARY"],
event["LOCATION"],
event["DESCRIPTION"],
event["UID"]
event["UID"],
flag_exam
)
events[e.uid] = e

31 changes: 20 additions & 11 deletions src/Event.py
Original file line number Diff line number Diff line change
@@ -48,31 +48,37 @@ def __hash__(self) -> int:

def __str__(self) -> str:
"""Permet d'avoir une str pour représenter l'Event."""
event = f"{self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")} : {self.group.value}{f" {"INGE" if self.isINGE else ""}{"-" if self.isINGE and self.isMIAGE else ""}{"MIAGE" if self.isMIAGE else ""}" if self.group.value == "CM" else ""} - {self.subject} - {self.location} - {self.teacher}"
if self.isEXAM:
return ":warning: " + (f"{self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")} : {self.subject} - {f" {"INGE" if self.isINGE else ""}{"-" if self.isINGE and self.isMIAGE else ""}{"MIAGE" if self.isMIAGE else ""}" if self.group.value == "CM" else ""} - {self.location} - {self.teacher}".upper()) + " :warning:"
return ":warning: " + (event.upper()) + " :warning:"
else:
return f"{self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")} : {self.group.value}{f" {"INGE" if self.isINGE else ""}{"-" if self.isINGE and self.isMIAGE else ""}{"MIAGE" if self.isMIAGE else ""}" if self.group.value == "CM" else ""} - {self.subject} - {self.location} - {self.teacher}"
return event

def str_day(self, autre: 'Event' = None) -> str:
"""Permet de comparer deux Event et de renvoyer une str de l'événement self avec les éléments qui changent en gars."""
defaut = f"{weekday[self.start_timestamp.weekday()]} {self.start_timestamp.strftime("%d-%m-%Y")} {self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")} : {self.group.value}{f" {"INGE" if self.isINGE else ""}{"-" if self.isINGE and self.isMIAGE else ""}{"MIAGE" if self.isMIAGE else ""}" if self.group.value == "CM" else ""} - {self.subject} - {self.location} - {self.teacher}"

if autre is None:
if self.isEXAM:
return ":warning: " + (f"{weekday[self.start_timestamp.weekday()]} {self.start_timestamp.strftime("%d-%m-%Y")} {self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")} : {self.subject} - {f" {"INGE" if self.isINGE else ""}{"-" if self.isINGE and self.isMIAGE else ""}{"MIAGE" if self.isMIAGE else ""}" if self.group.value == "CM" else ""} - {self.location} - {self.teacher}".upper()) + " :warning:"
return ":warning: " + defaut + " :warning:"
else:
return f"{weekday[self.start_timestamp.weekday()]} {self.start_timestamp.strftime("%d-%m-%Y")} {self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")} : {self.group.value}{f" {"INGE" if self.isINGE else ""}{"-" if self.isINGE and self.isMIAGE else ""}{"MIAGE" if self.isMIAGE else ""}" if self.group.value == "CM" else ""} - {self.subject} - {self.location} - {self.teacher}"
return defaut

texte = ""

day=f"{weekday[self.start_timestamp.weekday()]} {self.start_timestamp.strftime("%d-%m-%Y")} "

if(self.start_timestamp.strftime("%d-%m-%Y")) != (autre.start_timestamp.strftime("%d-%m-%Y")):
texte += f"**{weekday[self.start_timestamp.weekday()]} {self.start_timestamp.strftime("%d-%m-%Y")}** "
texte += f"**{day}**"
else:
texte += f"{weekday[self.start_timestamp.weekday()]} {self.start_timestamp.strftime("%d-%m-%Y")} "
texte += day

time=f"{self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")}"

if (self.start_timestamp.strftime("%Hh%M")) != (autre.start_timestamp.strftime("%Hh%M")):
texte += f"**{self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")}**"
texte += f"**{time}**"
else:
texte += f"{self.start_timestamp.strftime("%Hh%M")}-{self.end_timestamp.strftime("%Hh%M")}"
texte += time

texte += " : "

@@ -105,7 +111,7 @@ def str_day(self, autre: 'Event' = None) -> str:
texte += self.teacher

if self.isEXAM:
return ":warning: " + (texte.upper()) + " :warning:"
return f":warning: {texte.upper()} :warning:"
else:
return texte

@@ -129,7 +135,7 @@ def ics(self) -> str:
return ics


def get_event_from_data(start:datetime, end:datetime, sum:str, loc:str, desc:str, uid:str) -> Event:
def get_event_from_data(start:datetime, end:datetime, sum:str, loc:str, desc:str, uid:str, flag_exam: list[str]) -> Event:
"""Permet d'extraire les informations des données parsées."""
# Événements spéciaux.
if sum == "Réunion rentrée - L3 INGENIERIE INFORMATIQUE":
@@ -152,6 +158,9 @@ def get_event_from_data(start:datetime, end:datetime, sum:str, loc:str, desc:str
teacher = descsplit[-3].replace("\n", "").removeprefix(" ") if descsplit[-3] != "L3 INFORMAT-UPEX MINERVE" else "Enseignant ?"
location = loc if not loc == "" else "Salle ?"

is_exam = uid in flag_exam


# Valeur par défaut.
isMIAGE = False
isINGE = False
@@ -251,4 +260,4 @@ def get_event_from_data(start:datetime, end:datetime, sum:str, loc:str, desc:str
sentry_sdk.capture_exception(exception)

# Crée un nouvel Objet Event à partir des infos calculées.
return Event(start, end, subject, group, location, teacher, isINGE, isMIAGE, uid)
return Event(start, end, subject, group, location, teacher, isINGE, isMIAGE, uid, is_exam)
13 changes: 11 additions & 2 deletions src/MyTask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from interactions import Client, Task, TimeTrigger, OrTrigger, Embed, Extension, slash_command, SlashContext, \
Permissions, AllowedMentions, ContextType
from datetime import datetime
@@ -35,9 +37,16 @@ async def update_calendar(self) -> None:
# sup :set[Event] = set()
# add :set[Event] = set()
# mod :set[(Event,Event)] = set()

channels = self.bot.guilds[0].channels
arguement: dict[str:dict[str:str]] = None
for channel in channels:
if channel.name =="arguement-bot":
arguement = json.loads((await channel.fetch_message(channel.last_message_id)).content)

await self.bot.get_channel(os.getenv("ERROR_CHANNEL_ID")).send("Exécution de `update_calendar`")
old_calendar = Calendar(False)
new_calendar = Calendar(True)
old_calendar = Calendar(False, list(arguement.get("exam_list").values()))
new_calendar = Calendar(True, list(arguement.get("exam_list").values()))
await self.bot.get_channel(os.getenv("ERROR_CHANNEL_ID")).send(f"Fichier du {datetime.now()}", files=["data/INGE.ics", "data/MIAGE.ics"])
sup, add, mod, changed_id = changed_events(old_calendar, new_calendar)

0 comments on commit 1986c5a

Please sign in to comment.