Création module 'date_tools'
Création programme principal en CLI 'main_cli' Création de la liste des salles 'rooms.txt' Création du module de récupération des salles 'rooms_get' Nouveau nom : 'UniSquat'
This commit is contained in:
parent
e8eefcbb85
commit
63b91519d2
106
date_tools.py
Normal file
106
date_tools.py
Normal file
@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Feb 24 16:36:32 2022
|
||||
|
||||
@author: antoine
|
||||
"""
|
||||
|
||||
########################
|
||||
### Module datetools ###
|
||||
########################
|
||||
|
||||
"""
|
||||
Diverses fonctions relatives à la date du jour et à l'heure.
|
||||
"""
|
||||
|
||||
|
||||
# Modules :
|
||||
import datetime
|
||||
|
||||
|
||||
# Fonctions :
|
||||
|
||||
def is_bissextile(year) :
|
||||
"""
|
||||
|
||||
Indique si l'année 'year' est bissextile ou non.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
year : int
|
||||
Année dont on veut vérifier la bissextilité.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
'True' si 'year' est bissextile, 'False' sinon.
|
||||
|
||||
"""
|
||||
|
||||
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0 :
|
||||
return True
|
||||
else :
|
||||
return False
|
||||
|
||||
|
||||
def month_days(month, year) :
|
||||
"""
|
||||
Renvoie le nombre de jours dans le mois 'month'.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
month : int (between 1 and 12)
|
||||
Mois dont on veut connaître le nombre de jours.
|
||||
year : int
|
||||
Année, pour vérifier la bissextilité (cas du mois de février).
|
||||
|
||||
Returns
|
||||
-------
|
||||
int
|
||||
Nombre de jours dans 'month'.
|
||||
|
||||
"""
|
||||
|
||||
if month == 2 :
|
||||
if bissextile(year) :
|
||||
return 29
|
||||
else :
|
||||
return 28
|
||||
elif month in (4,6,9,11) :
|
||||
return 30
|
||||
else :
|
||||
return 31
|
||||
|
||||
|
||||
def date_input() :
|
||||
"""
|
||||
Demande à l'utilisateur d'entrer une date (jour, mois, année,
|
||||
heure, minutes).
|
||||
|
||||
Returns
|
||||
-------
|
||||
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)
|
56
edt.txt
56
edt.txt
@ -1,56 +0,0 @@
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:PUBLISH
|
||||
PRODID:-//ADE/version 6.0
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:20220224T084154Z
|
||||
DTSTART:20220224T150000Z
|
||||
DTEND:20220224T170000Z
|
||||
SUMMARY:Architecture TD1
|
||||
LOCATION:C10 MATH
|
||||
DESCRIPTION:\n\nTP1 S3-P\nTP2 S3-P\n\n(Modifié le:24/01/2022 16:40)
|
||||
UID:ADE60556e6973747261323032312d323032322d33323736342d332d30
|
||||
CREATED:19700101T000000Z
|
||||
LAST-MODIFIED:20220124T154000Z
|
||||
SEQUENCE:-2092507296
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:20220224T084154Z
|
||||
DTSTART:20220224T090000Z
|
||||
DTEND:20220224T110000Z
|
||||
SUMMARY:MPA - Algèbre jeudi S2
|
||||
LOCATION:C10 MATH
|
||||
DESCRIPTION:\n\nL1 MPA\nGasbarri Carlo\n\n(Modifié le:29/11/2021 12:51)
|
||||
UID:ADE60556e6973747261323032312d323032322d34393538362d342d30
|
||||
CREATED:19700101T000000Z
|
||||
LAST-MODIFIED:20211129T115100Z
|
||||
SEQUENCE:2133346260
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:20220224T084154Z
|
||||
DTSTART:20220224T130000Z
|
||||
DTEND:20220224T144500Z
|
||||
SUMMARY:2- Maths pour les Sciences 2 PY-1 (Jeu 14h-15h30)
|
||||
LOCATION:C10 MATH
|
||||
DESCRIPTION:\n\nPY-1\nL1 Double licence PHY-STUE\nLançon Ariane\n\n(Modif
|
||||
ié le:26/01/2022 21:29)
|
||||
UID:ADE60556e6973747261323032312d323032322d3131353739392d332d30
|
||||
CREATED:19700101T000000Z
|
||||
LAST-MODIFIED:20220126T202900Z
|
||||
SEQUENCE:-2092289956
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:20220224T084154Z
|
||||
DTSTART:20220224T070000Z
|
||||
DTEND:20220224T090000Z
|
||||
SUMMARY:Probabilités S6 - CM
|
||||
LOCATION:C10 MATH
|
||||
DESCRIPTION:\n\nL3-M-S6-Maths pures\nL3-MAG S6\nZeng Xiaolin\n\n(Modifié
|
||||
le:09/02/2022 13:23)
|
||||
UID:ADE60556e6973747261323032312d323032322d36323034302d342d30
|
||||
CREATED:19700101T000000Z
|
||||
LAST-MODIFIED:20220209T122300Z
|
||||
SEQUENCE:-2090919116
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Feb 24 08:51:58 2022
|
||||
|
||||
@author: antoine
|
||||
"""
|
||||
|
||||
import requests
|
||||
|
||||
import datetime
|
||||
|
||||
date = datetime.datetime.today().date()
|
||||
|
||||
day = str(date.day)
|
||||
month = str(date.month)
|
||||
year = str(date.year)
|
||||
|
||||
f = open("edt.txt", "w")
|
||||
|
||||
r = requests.get("https://adecons.unistra.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources=5448&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=5448&projectId=8&calType=ical&firstDate=2022-02-25&lastDate=2022-02-25')
|
||||
#r = requests.get('https://adecons.unistra.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources=5448&projectId=8&calType=ical&nbWeeks=4')
|
||||
edt = str(r.text)
|
||||
|
||||
f.writelines(edt)
|
||||
|
||||
f.close()
|
62
main_cli.py
Normal file
62
main_cli.py
Normal file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Feb 24 17:14:05 2022
|
||||
|
||||
@author: antoine
|
||||
"""
|
||||
|
||||
################
|
||||
### UniSquat ###
|
||||
################
|
||||
|
||||
"""
|
||||
Indique toutes les salles disponibles dans les différents départements de
|
||||
l'Université de Strasbourg.
|
||||
"""
|
||||
|
||||
|
||||
# Modules :
|
||||
import datetime
|
||||
import date_tools
|
||||
import rooms_get as ro
|
||||
|
||||
|
||||
# Fonctions :
|
||||
|
||||
def main() :
|
||||
"""
|
||||
Fonction principale.
|
||||
|
||||
Returns
|
||||
-------
|
||||
None.
|
||||
|
||||
"""
|
||||
|
||||
print("~~~ UniSquat ~~~\n")
|
||||
|
||||
date_choice = 0
|
||||
|
||||
while date_choice not in (1,2) :
|
||||
date_choice = int(input("Souhaitez-vous afficher les salles disponibles maintenant (1), où à une date précise (2) ?\n> "))
|
||||
|
||||
if date_choice == 1 :
|
||||
date = datetime.datetime
|
||||
date_d = date.today().date()
|
||||
datet = date.today()
|
||||
else :
|
||||
date = date_tools.date_input()
|
||||
date_d = date.today().date()
|
||||
datet = date.today()
|
||||
|
||||
hour = date.now().time().hour
|
||||
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)
|
||||
|
||||
print("Les salles suivantes sont disponibles à " + str(hour) + ":" + str(minutes) + ", le " + str(date_d) + " :\n")
|
||||
for room in available_rooms :
|
||||
print(" - " + room)
|
34
rooms.txt
Normal file
34
rooms.txt
Normal file
@ -0,0 +1,34 @@
|
||||
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)
|
124
rooms_get.py
Normal file
124
rooms_get.py
Normal file
@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Feb 24 08:51:58 2022
|
||||
|
||||
@author: antoine
|
||||
"""
|
||||
|
||||
################
|
||||
### UniSquat ###
|
||||
################
|
||||
|
||||
"""
|
||||
Indique toutes les salles disponibles dans les différents départements de
|
||||
l'Université de Strasbourg.
|
||||
"""
|
||||
|
||||
|
||||
# Modules :
|
||||
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) :
|
||||
"""
|
||||
Récupère l'emploi du temps de toutes les salles (pour le moment, juste
|
||||
de l'UFR) sur ADE depuis le site de l'Unistra.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
date : datetime.datetime()
|
||||
Date au format datetime.
|
||||
|
||||
Returns
|
||||
-------
|
||||
None.
|
||||
|
||||
"""
|
||||
|
||||
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()
|
||||
|
||||
|
||||
def used_rooms_get(datet) :
|
||||
"""
|
||||
Créé la liste des salles occupées à la date 'datet' d'après
|
||||
l'emploi du temps des salles.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
datet : datetime.datetime()
|
||||
Date au format datetime.
|
||||
|
||||
Returns
|
||||
-------
|
||||
used_rooms : list
|
||||
Liste des salles occupées.
|
||||
|
||||
"""
|
||||
|
||||
# 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())
|
||||
|
||||
used_rooms = []
|
||||
|
||||
for comp in cal.walk():
|
||||
if comp.name == "VEVENT" :
|
||||
ev_dstart = comp.decoded("dtstart")
|
||||
ev_dend = comp.decoded("dtend")
|
||||
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
|
||||
|
||||
|
||||
def available_rooms_get(used_rooms) :
|
||||
"""
|
||||
Créé la liste des salles disponibles d'après la liste des salles occupées
|
||||
'used_rooms'.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
used_rooms : list
|
||||
Liste des salles occupées.
|
||||
|
||||
Returns
|
||||
-------
|
||||
available_rooms : list
|
||||
Liste des salles disponibles.
|
||||
|
||||
"""
|
||||
|
||||
available_rooms = []
|
||||
|
||||
for room in rooms :
|
||||
if room not in used_rooms :
|
||||
available_rooms.append(room)
|
||||
|
||||
return available_rooms
|
1153
schedule.ics
Normal file
1153
schedule.ics
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user