100 lines
3.9 KiB
Python
100 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.
|
|
"""
|
|
|
|
|
|
### Fichier de l'interface graphique Qt ###
|
|
|
|
|
|
# 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"] # TODO : à enlever
|
|
links = []
|
|
|
|
|
|
def main() :
|
|
app = qt.QtWidgets.QApplication(sys.argv)
|
|
windows = qt.QtWidgets.QWidget()
|
|
|
|
windows.resize(500,500)
|
|
windows.move(100,100)
|
|
|
|
layout = qt.QtWidgets.QVBoxLayout()
|
|
|
|
date = datetime.datetime.today()
|
|
available_rooms = ro.getrooms(date,links=links)
|
|
|
|
button = qt.QtWidgets.QPushButton("Hello World !")
|
|
label1 = qt.QtWidgets.QLabel()
|
|
label1.setText("Maintenant :")
|
|
label2 = qt.QtWidgets.QLabel()
|
|
label2.setText("Prochainement :")
|
|
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"] + "\nOccupé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"
|
|
|
|
if room["end"].hour == 23 and room["end"].minute == 59 :
|
|
listwidget2.addItem(room["name"] + "\nLibre à " + 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"] + "\nLibre 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(label1)
|
|
layout.addWidget(listwidget1)
|
|
layout.addWidget(label2)
|
|
layout.addWidget(listwidget2)
|
|
|
|
windows.setLayout(layout)
|
|
|
|
windows.show()
|
|
sys.exit(app.exec_())
|
|
|
|
|
|
if __name__=="__main__":
|
|
main() |