This commit is contained in:
Antoine Waehren 2022-02-24 18:50:17 +01:00
commit 018fbd6bbd
5 changed files with 40 additions and 1241 deletions

View File

@ -23,7 +23,7 @@ import datetime
def is_bissextile(year) :
"""
Indique si l'année 'year' est bissextile ou non.
Parameters
@ -37,12 +37,8 @@ def is_bissextile(year) :
'True' si 'year' est bissextile, 'False' sinon.
"""
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0 :
return True
else :
return False
return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0
def month_days(month, year) :
"""
@ -61,7 +57,7 @@ def month_days(month, year) :
Nombre de jours dans 'month'.
"""
if month == 2 :
if bissextile(year) :
return 29
@ -71,7 +67,7 @@ def month_days(month, year) :
return 30
else :
return 31
def date_input() :
"""
@ -83,24 +79,24 @@ def date_input() :
datetime.datetime()
Date entrée au format datetime.
"""
year = int(input("Entrer l'année.\n> "))
month = 0
while month not in range(1, 13) :
month = int(input("Entrer le mois.\n"))
mdays = month_days(month, year)
day = 0
while day not in range(1, mdays + 1) :
day = int(input("Entrer le jour.\n> "))
hour = -1
while hour not in range(0, 25) :
hour = int(input("Entrer l'heure.\n> "))
minute = -1
while minute not in range(0, 60) :
minute = int(input("Entrer les minutes.\n> "))
return datetime.datetime(year, month, day, hour, minute)
return datetime.datetime(year, month, day, hour, minute)

View File

@ -54,9 +54,9 @@ def main() :
minutes = date.now().time().minute
ro.sched_get(date_d)
used_rooms = ro.used_rooms_get(datet)
available_rooms = ro.available_rooms_get(used_rooms)
total_rooms, used_rooms = ro.used_rooms_get(datet)
available_rooms = ro.available_rooms_get(total_rooms, used_rooms)
print("Les salles suivantes sont disponibles à " + str(hour) + ":" + str(minutes) + ", le " + str(date_d) + " :\n")
for room in available_rooms :
print(" - " + room)
print(" - " + room)

View File

@ -1,34 +0,0 @@
C10 MATH
C11 MATH
C13 MATH
C14 MATH
C15 MATH
C1 MATH
C31-GPI
C31-GPI,C14 MATH
C32-MF
C33-DUAS
C41-MPA
C42-CMI
C4 MATH
C5 MATH
C6 MATH
C7 MATH
C7 MATH,salle non définie
C8 MATH
C9 MATH
Grand Amphi de Maths-Frenkel
Petit Amphi de Maths
S. 301 MATH
S. 309
S. 418
T01 MATH
T02 MATH
T03 MATH
T11 MATH
T20 MATH (PC)
T21 MATH (PC)
T22 MATH (PC)
T23 MATH
T24 MATH
T40-GPI MATH (PC)

View File

@ -20,18 +20,9 @@ Created on Thu Feb 24 08:51:58 2022
import requests
import icalendar
# Variables générales :
sched_filen = "schedule.ics"
rooms_filen = "rooms.txt"
# Récupération des salles :
r_file = open(rooms_filen, "r")
rooms = r_file.read().splitlines()
r_file.close()
# Fonctions :
def sched_get(date) :
@ -46,20 +37,17 @@ def sched_get(date) :
Returns
-------
None.
Le texte du résultat de la requête.
"""
day = str(date.day)
month = str(date.month)
year = str(date.year)
r = requests.get("https://adecons.unistra.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources=30626&projectId=8&calType=ical&firstDate="+year+"-"+month+"-"+day+"&lastDate="+year+"-"+month+"-"+day)
# Téléchargement au format iCal
f = open(sched_filen, "wb")
f.write(r.content)
f.close()
return r.content
def used_rooms_get(datet) :
@ -75,30 +63,30 @@ def used_rooms_get(datet) :
Returns
-------
used_rooms : list
Liste des salles occupées.
Liste des salles occupées. total_rooms : list
Toutes les salles mentionnées dans le fichier
"""
# Récupération des informations sur l'EDT téléchargé :
cal_file = open(sched_filen, "rb")
cal = icalendar.Calendar.from_ical(cal_file.read())
cal = icalendar.Calendar.from_ical(sched_get(datet))
used_rooms = []
total_rooms = []
for comp in cal.walk():
if comp.name == "VEVENT" :
ev_dstart = comp.decoded("dtstart")
ev_dend = comp.decoded("dtend")
roomname = str(comp.get("location"))
if not roomname in total_rooms:
total_rooms.append(roomname)
if ev_dstart.timestamp() <= datet.timestamp() and ev_dend.timestamp() > datet.timestamp() :
if comp.get("location") not in used_rooms :
used_rooms.append(str(comp.get("location")))
cal_file.close()
return used_rooms
if not roomname in used_rooms :
used_rooms.append(roomname)
return total_rooms, used_rooms
def available_rooms_get(used_rooms) :
def available_rooms_get(total_rooms, used_rooms) :
"""
Créé la liste des salles disponibles d'après la liste des salles occupées
'used_rooms'.
@ -107,6 +95,8 @@ def available_rooms_get(used_rooms) :
----------
used_rooms : list
Liste des salles occupées.
total_rooms : list
Liste de toute les salles
Returns
-------
@ -114,11 +104,11 @@ def available_rooms_get(used_rooms) :
Liste des salles disponibles.
"""
available_rooms = []
for room in rooms :
for room in total_rooms :
if room not in used_rooms :
available_rooms.append(room)
return available_rooms
return available_rooms

File diff suppressed because it is too large Load Diff