2022-03-03 09:53:47 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 3 08 : 47 : 47 2022
@author : antoine
"""
################
### UniSquat ###
################
"""
2022-06-17 19:12:29 +02:00
Une application pour afficher les salles libres dans les différents
départements de l ' Université de Strasbourg.
2022-03-03 09:53:47 +01:00
"""
2022-05-12 15:32:12 +02:00
### Fichier de l'interface graphique Qt ###
2022-03-03 09:53:47 +01:00
2022-05-12 15:32:12 +02:00
# Modules :
2022-03-03 09:53:47 +01:00
import sys
import PyQt5 as qt
import rooms_get as ro
import datetime
import date_tools
2022-05-12 15:32:12 +02:00
favorites = [ " C " + str ( i ) + " MATH " for i in range ( 1 , 10 ) ] + [ " C42-CMI " ] # TODO : à enlever
2022-03-03 09:53:47 +01:00
links = [ ]
2022-05-12 15:32:12 +02:00
2022-03-03 09:53:47 +01:00
def main ( ) :
app = qt . QtWidgets . QApplication ( sys . argv )
windows = qt . QtWidgets . QWidget ( )
windows . resize ( 500 , 500 )
windows . move ( 100 , 100 )
2022-03-03 09:59:59 +01:00
layout = qt . QtWidgets . QVBoxLayout ( )
2022-03-03 09:53:47 +01:00
date = datetime . datetime . today ( )
available_rooms = ro . getrooms ( date , links = links )
2022-03-03 09:59:59 +01:00
label1 = qt . QtWidgets . QLabel ( )
2022-03-03 10:14:43 +01:00
label1 . setText ( " Maintenant : " )
2022-03-03 09:59:59 +01:00
label2 = qt . QtWidgets . QLabel ( )
2022-03-03 10:14:43 +01:00
label2 . setText ( " Prochainement : " )
2022-03-03 09:53:47 +01:00
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 :
2022-03-03 10:14:43 +01:00
listwidget1 . addItem ( room [ " name " ] )
2022-03-03 09:53:47 +01:00
else :
2022-03-03 10:14:43 +01:00
listwidget1 . addItem ( room [ " name " ] + " \n 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 ?)
2022-03-03 09:53:47 +01:00
# 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 :
2022-03-03 10:14:43 +01:00
listwidget2 . addItem ( room [ " name " ] + " \n Libre à " + str ( room [ " start " ] . hour + 1 ) + " : " + str ( room [ " start " ] . minute ) + " (dans " + remain_time_str + " ) " ) # TODO : Obligé d'ajouter 1h (problème de fuseau horaire ?)
2022-03-03 09:53:47 +01:00
else :
2022-03-03 10:14:43 +01:00
listwidget2 . addItem ( room [ " name " ] + " \n 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 ?)
2022-03-03 09:53:47 +01:00
2022-03-03 09:59:59 +01:00
layout . addWidget ( label1 )
2022-03-03 09:53:47 +01:00
layout . addWidget ( listwidget1 )
2022-03-03 09:59:59 +01:00
layout . addWidget ( label2 )
2022-03-03 09:53:47 +01:00
layout . addWidget ( listwidget2 )
windows . setLayout ( layout )
windows . show ( )
sys . exit ( app . exec_ ( ) )
2022-05-12 15:32:12 +02:00
2022-03-03 09:53:47 +01:00
if __name__ == " __main__ " :
main ( )