Merge branch 'master' of https://forge.chapril.org/CretinsMotorisesIngenieux/FreeRooms_Unistra
This commit is contained in:
commit
018fbd6bbd
@ -23,7 +23,7 @@ import datetime
|
|||||||
|
|
||||||
def is_bissextile(year) :
|
def is_bissextile(year) :
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Indique si l'année 'year' est bissextile ou non.
|
Indique si l'année 'year' est bissextile ou non.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -37,12 +37,8 @@ def is_bissextile(year) :
|
|||||||
'True' si 'year' est bissextile, 'False' sinon.
|
'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) :
|
def month_days(month, year) :
|
||||||
"""
|
"""
|
||||||
@ -61,7 +57,7 @@ def month_days(month, year) :
|
|||||||
Nombre de jours dans 'month'.
|
Nombre de jours dans 'month'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if month == 2 :
|
if month == 2 :
|
||||||
if bissextile(year) :
|
if bissextile(year) :
|
||||||
return 29
|
return 29
|
||||||
@ -71,7 +67,7 @@ def month_days(month, year) :
|
|||||||
return 30
|
return 30
|
||||||
else :
|
else :
|
||||||
return 31
|
return 31
|
||||||
|
|
||||||
|
|
||||||
def date_input() :
|
def date_input() :
|
||||||
"""
|
"""
|
||||||
@ -83,24 +79,24 @@ def date_input() :
|
|||||||
datetime.datetime()
|
datetime.datetime()
|
||||||
Date entrée au format datetime.
|
Date entrée au format datetime.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
year = int(input("Entrer l'année.\n> "))
|
year = int(input("Entrer l'année.\n> "))
|
||||||
|
|
||||||
month = 0
|
month = 0
|
||||||
while month not in range(1, 13) :
|
while month not in range(1, 13) :
|
||||||
month = int(input("Entrer le mois.\n"))
|
month = int(input("Entrer le mois.\n"))
|
||||||
|
|
||||||
mdays = month_days(month, year)
|
mdays = month_days(month, year)
|
||||||
day = 0
|
day = 0
|
||||||
while day not in range(1, mdays + 1) :
|
while day not in range(1, mdays + 1) :
|
||||||
day = int(input("Entrer le jour.\n> "))
|
day = int(input("Entrer le jour.\n> "))
|
||||||
|
|
||||||
hour = -1
|
hour = -1
|
||||||
while hour not in range(0, 25) :
|
while hour not in range(0, 25) :
|
||||||
hour = int(input("Entrer l'heure.\n> "))
|
hour = int(input("Entrer l'heure.\n> "))
|
||||||
|
|
||||||
minute = -1
|
minute = -1
|
||||||
while minute not in range(0, 60) :
|
while minute not in range(0, 60) :
|
||||||
minute = int(input("Entrer les minutes.\n> "))
|
minute = int(input("Entrer les minutes.\n> "))
|
||||||
|
|
||||||
return datetime.datetime(year, month, day, hour, minute)
|
return datetime.datetime(year, month, day, hour, minute)
|
||||||
|
@ -54,9 +54,9 @@ def main() :
|
|||||||
minutes = date.now().time().minute
|
minutes = date.now().time().minute
|
||||||
|
|
||||||
ro.sched_get(date_d)
|
ro.sched_get(date_d)
|
||||||
used_rooms = ro.used_rooms_get(datet)
|
total_rooms, used_rooms = ro.used_rooms_get(datet)
|
||||||
available_rooms = ro.available_rooms_get(used_rooms)
|
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")
|
print("Les salles suivantes sont disponibles à " + str(hour) + ":" + str(minutes) + ", le " + str(date_d) + " :\n")
|
||||||
for room in available_rooms :
|
for room in available_rooms :
|
||||||
print(" - " + room)
|
print(" - " + room)
|
||||||
|
34
rooms.txt
34
rooms.txt
@ -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)
|
|
62
rooms_get.py
62
rooms_get.py
@ -20,18 +20,9 @@ Created on Thu Feb 24 08:51:58 2022
|
|||||||
import requests
|
import requests
|
||||||
import icalendar
|
import icalendar
|
||||||
|
|
||||||
|
|
||||||
# Variables générales :
|
# Variables générales :
|
||||||
sched_filen = "schedule.ics"
|
|
||||||
rooms_filen = "rooms.txt"
|
rooms_filen = "rooms.txt"
|
||||||
|
|
||||||
|
|
||||||
# Récupération des salles :
|
|
||||||
r_file = open(rooms_filen, "r")
|
|
||||||
rooms = r_file.read().splitlines()
|
|
||||||
r_file.close()
|
|
||||||
|
|
||||||
|
|
||||||
# Fonctions :
|
# Fonctions :
|
||||||
|
|
||||||
def sched_get(date) :
|
def sched_get(date) :
|
||||||
@ -46,20 +37,17 @@ def sched_get(date) :
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
None.
|
Le texte du résultat de la requête.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
day = str(date.day)
|
day = str(date.day)
|
||||||
month = str(date.month)
|
month = str(date.month)
|
||||||
year = str(date.year)
|
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)
|
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
|
return r.content
|
||||||
f = open(sched_filen, "wb")
|
|
||||||
f.write(r.content)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def used_rooms_get(datet) :
|
def used_rooms_get(datet) :
|
||||||
@ -75,30 +63,30 @@ def used_rooms_get(datet) :
|
|||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
used_rooms : list
|
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é :
|
# Récupération des informations sur l'EDT téléchargé :
|
||||||
cal_file = open(sched_filen, "rb")
|
cal = icalendar.Calendar.from_ical(sched_get(datet))
|
||||||
cal = icalendar.Calendar.from_ical(cal_file.read())
|
|
||||||
|
|
||||||
used_rooms = []
|
used_rooms = []
|
||||||
|
total_rooms = []
|
||||||
|
|
||||||
for comp in cal.walk():
|
for comp in cal.walk():
|
||||||
if comp.name == "VEVENT" :
|
if comp.name == "VEVENT" :
|
||||||
ev_dstart = comp.decoded("dtstart")
|
ev_dstart = comp.decoded("dtstart")
|
||||||
ev_dend = comp.decoded("dtend")
|
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 ev_dstart.timestamp() <= datet.timestamp() and ev_dend.timestamp() > datet.timestamp() :
|
||||||
if comp.get("location") not in used_rooms :
|
if not roomname in used_rooms :
|
||||||
used_rooms.append(str(comp.get("location")))
|
used_rooms.append(roomname)
|
||||||
|
|
||||||
cal_file.close()
|
|
||||||
|
|
||||||
return used_rooms
|
|
||||||
|
|
||||||
|
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
|
Créé la liste des salles disponibles d'après la liste des salles occupées
|
||||||
'used_rooms'.
|
'used_rooms'.
|
||||||
@ -107,6 +95,8 @@ def available_rooms_get(used_rooms) :
|
|||||||
----------
|
----------
|
||||||
used_rooms : list
|
used_rooms : list
|
||||||
Liste des salles occupées.
|
Liste des salles occupées.
|
||||||
|
total_rooms : list
|
||||||
|
Liste de toute les salles
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@ -114,11 +104,11 @@ def available_rooms_get(used_rooms) :
|
|||||||
Liste des salles disponibles.
|
Liste des salles disponibles.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
available_rooms = []
|
available_rooms = []
|
||||||
|
|
||||||
for room in rooms :
|
for room in total_rooms :
|
||||||
if room not in used_rooms :
|
if room not in used_rooms :
|
||||||
available_rooms.append(room)
|
available_rooms.append(room)
|
||||||
|
|
||||||
return available_rooms
|
return available_rooms
|
||||||
|
1153
schedule.ics
1153
schedule.ics
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user