from flask import * from base64 import b64decode, b64encode from time import ctime, sleep, time from threading import Thread import gzip, requests from getFreeRoomsFromAde2 import AdeRequest Ade = AdeRequest() infos = Ade.getRoomsInfos() freeRooms = Ade.getCurrentsFreeRooms() def import_allowed(): tab = [] for room in freeRooms: tab.append([room, freeRooms[room]["freeUntil"]]) return tab def import_response_data(): tab = [] for room in freeRooms: tab.append([room, freeRooms[room]["capacity"], freeRooms[room]["freeUntil"], freeRooms[room]["busy"]]) return tab app = Flask(__name__) app.config['response_data'] = import_response_data() # [numRoom: str, capacity: int, freeUntil: str, busy: tuple] app.config['allowed'] = import_allowed() # [numRoom: str, freeUtil: str] def reloadData(): while True: try: sleep(600) infos = Ade.getRoomsInfos() freeRooms = Ade.getCurrentsFreeRooms() app.config['response_data'] = import_response_data() # [numRoom: str, capacity: int, freeUntil: str, busy: tuple] app.config['allowed'] = import_allowed() # [numRoom: str, freeUtil: str] print("[+] Refresh Data From Ade") except Exception as e: print("Err. When reload:", e) Thread(target=reloadData).start() @app.route('/') def index(): prepPage = "" deux = "" for ip in app.config["allowed"]: prepPage += "
Salle n°" + ipPadded + "
\n" prepPage += "Disponible jusqu'à -> " + ip[1] + "
\n" prepPage += "