from flask import * from base64 import b64decode, b64encode from time import ctime, sleep, time from threading import Thread from datetime import datetime, timezone import gzip, requests, json from getFreeRoomsFromAde2 import AdeRequest Ade = AdeRequest() infos = Ade.getRoomsInfos() global freeRooms freeRooms = Ade.getCurrentsFreeRooms() def import_allowed(): global freeRooms tab = [] for room in freeRooms: tab.append([room, freeRooms[room]["freeUntil"]]) return tab def import_response_data(): global freeRooms 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(): global freeRooms while True: try: #sleep(600) if datetime.now().minute % 20 == 0: Ade = AdeRequest() 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("[" + datetime.now().strftime("%y/%m/%d %H:%M:%S") + "] Refresh Data From Ade") sleep(120) sleep(10) except Exception as e: print("Err. When reload:", e) sleep(30) 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 += "