93 lines
3.9 KiB
Python
93 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Thu Mar 3 08:47:47 2022
|
|
|
|
@author: antoine
|
|
"""
|
|
|
|
################
|
|
### UniSquat ###
|
|
################
|
|
|
|
"""
|
|
Indique toutes les salles disponibles dans les différents départements de
|
|
l'Université de Strasbourg.
|
|
"""
|
|
|
|
|
|
# Modules :
|
|
|
|
import sys
|
|
import PyQt5 as qt
|
|
import rooms_get as ro
|
|
import datetime
|
|
import date_tools
|
|
|
|
favorites = ["C"+str(i)+" MATH" for i in range(1,10)]+["C42-CMI"]
|
|
links = []
|
|
|
|
def main() :
|
|
app = qt.QtWidgets.QApplication(sys.argv)
|
|
windows = qt.QtWidgets.QWidget()
|
|
|
|
windows.resize(500,500)
|
|
windows.move(100,100)
|
|
|
|
layout = qt.QtWidgets.QHBoxLayout()
|
|
|
|
date = datetime.datetime.today()
|
|
available_rooms = ro.getrooms(date,links=links)
|
|
|
|
button = qt.QtWidgets.QPushButton("Hello World !")
|
|
label = qt.QtWidgets.QLabel()
|
|
label.setText("Les salles suivantes sont disponibles à " + str(date.hour) + ":" + str(date.minute) + ", le " + str(date.date()) + " :")
|
|
listwidget1 = qt.QtWidgets.QListWidget()
|
|
listwidget2 = qt.QtWidgets.QListWidget()
|
|
|
|
# Salles libres à la date indiquée :
|
|
for room in available_rooms.values() :
|
|
if room["name"] in favorites or len(favorites) == 0 : # TODO : Changer le comportement de ce 'if' : il faudrait afficher toutes les salles, mais d'abord les favorites
|
|
if room["is_free"] :
|
|
deltasec = room["end"].timestamp() - date.timestamp()
|
|
remain_time_str = str(int(deltasec / 60 + 0.5)) + " minutes"
|
|
if deltasec / 60 + 0.5 >= 60 : # Conversion en heures:minutes si les minutes dépassent 60
|
|
deltasec = date_tools.minutes_convert(deltasec / 60 + 0.5)
|
|
remain_time_str = str(deltasec[0]) + " heures"
|
|
if deltasec[1] > 0 :
|
|
remain_time_str += " " + str(deltasec[1]) + " minutes"
|
|
|
|
if room["end"].hour == 23 and room["end"].minute == 59 :
|
|
listwidget1.addItem(" - " + room["name"])
|
|
else :
|
|
listwidget1.addItem(" - " + room["name"] + " | occupée à : " + str(room["end"].hour + 1) + ":" + str(room["end"].minute) + " (dans " + remain_time_str + ")") # TODO : Obligé d'ajouter 1h (problème de fuseau horaire ?)
|
|
|
|
# Salles libres prochainement :
|
|
for room in available_rooms.values() :
|
|
if room["name"] in favorites or len(favorites) == 0 :
|
|
if not room["is_free"] :
|
|
deltasec = room["start"].timestamp() - date.timestamp()
|
|
remain_time_str = str(int(deltasec / 60 + 0.5)) + " minutes"
|
|
if deltasec / 60 + 0.5 >= 60 : # Conversion en heures:minutes si les minutes dépassent 60
|
|
deltasec = date_tools.minutes_convert(deltasec / 60 + 0.5)
|
|
remain_time_str = str(deltasec[0]) + " heures"
|
|
if deltasec[1] > 0 :
|
|
remain_time_str += " " + str(deltasec[1]) + " minutes"
|
|
|
|
# print(" - " + room["name"]+" | libre dans : "+str(int(deltasec/60+0.5))+" minutes")
|
|
if room["end"].hour == 23 and room["end"].minute == 59 :
|
|
listwidget2.addItem(" - " + room["name"] + " | libre à " + str(room["start"].hour + 1) + ":" + str(room["start"].minute) + " (dans " + remain_time_str + ")") # TODO : Obligé d'ajouter 1h (problème de fuseau horaire ?)
|
|
else :
|
|
listwidget2.addItem(" - " + room["name"] + " | libre de " + str(room["start"].hour + 1) + ":" + str(room["start"].minute) + " à " + str(room["end"].hour + 1) + ":" + str(room["end"].minute) + " (dans " + remain_time_str + ")") # TODO : Obligé d'ajouter 1h (problème de fuseau horaire ?)
|
|
|
|
layout.addWidget(label)
|
|
layout.addWidget(listwidget1)
|
|
layout.addWidget(listwidget2)
|
|
|
|
windows.setLayout(layout)
|
|
|
|
windows.show()
|
|
sys.exit(app.exec_())
|
|
|
|
if __name__=="__main__":
|
|
main() |