Compare commits

..

2 Commits

Author SHA1 Message Date
theo@manjaro ee35260d97 Fix du délai d'un mois 2024-03-31 21:43:55 +02:00
theo@manjaro dda111f4cf Ajout d'info git au contexte global 2024-03-22 16:59:00 +01:00
5 changed files with 65 additions and 43 deletions

15
app.py
View File

@ -16,6 +16,7 @@ import pytz
import json import json
import os import os
import traceback import traceback
import git
from flask import Flask from flask import Flask
from flask import render_template from flask import render_template
@ -68,6 +69,12 @@ GLOBAL_CONTEXT["DOMAIN"] = "https://unisquat.alwaysdata.net"
# Timezone du serveur : # Timezone du serveur :
TIMEZONE = pytz.timezone("Europe/Paris") TIMEZONE = pytz.timezone("Europe/Paris")
# Branche actuelle git
GLOBAL_CONTEXT["GIT_BRANCH"] = git.get_active_branch_name()
# Hash du commit actuel git
GLOBAL_CONTEXT["GIT_COMMIT"] = git.get_git_revision()
# Globales : # Globales :
app = Flask(__name__) app = Flask(__name__)
@ -76,11 +83,7 @@ app = Flask(__name__)
logs = [] logs = []
if os.path.isfile(LOG_FILE): if os.path.isfile(LOG_FILE):
with open(LOG_FILE,"r") as f: with open(LOG_FILE,"r") as f:
try: logs = json.loads(f.read())
logs = json.loads(f.read())
# On supprime le fichier s'il est invalide :
except json.decoder.JSONDecodeError:
os.remove(LOG_FILE)
# Fonctions : # Fonctions :
def save_logs(logs): def save_logs(logs):
@ -304,7 +307,7 @@ def free_rooms(api = False, rq = None) :
if GLOBAL_CONTEXT["DEBUG"] : if GLOBAL_CONTEXT["DEBUG"] :
print(errdetails) print(errdetails)
return render_template("error.html", return render_template("error.html",
error="Désolé, une erreur est survenue. UniSquat ne peut pas continuer.") error="Le serveur Unistra a rencontré une erreur ! Veuillez réessayer plus tard.")
# Création d'un dictionnaire avec les infos des salles : # Création d'un dictionnaire avec les infos des salles :
frooms_disp = dict() # Mise en forme des infos pour la page Web frooms_disp = dict() # Mise en forme des infos pour la page Web

22
git.py Normal file
View File

@ -0,0 +1,22 @@
from pathlib import Path
def get_active_branch_name(base_path="."):
head_dir = Path(base_path) / ".git" / "HEAD"
with head_dir.open("r") as f:
content = f.read().splitlines()
for line in content:
if line[0:4] == "ref:":
return line.partition("refs/heads/")[2]
def get_git_revision(base_path=".", short = True):
git_dir = Path(base_path) / '.git'
with (git_dir / 'HEAD').open('r') as head:
ref = head.readline().split(' ')[-1].strip()
with (git_dir / ref).open('r') as git_hash:
hash = git_hash.readline().strip()
if short:
return hash[:7]
else:
return hash

View File

@ -22,6 +22,7 @@ import pytz
import os import os
import shutil import shutil
import time import time
import datetime
# Fichiers locaux : # Fichiers locaux :
from objects import Room from objects import Room
@ -245,18 +246,12 @@ def get_tot_rooms(datet, depts, ignore_list) :
margintime = 1 margintime = 1
# Récupération du calendrier de chaque département, # Récupération du calendrier de chaque département,
# sur une période de 'margintime' mois. # sur une période de 'margintime' mois :
# On choisit comme jour le 28, car tous les mois ont au moins 28 jours.
cals = list() # Liste des EDT des départements choisis cals = list() # Liste des EDT des départements choisis
for d in depts : for d in depts :
if datet.month < 12 : result = sched_get(datet, d.link,
result = sched_get(datet, d.link, datet + datetime.timedelta(margintime),
datet.replace(day = 28, month = datet.month + margintime), NO_CACHE)
NO_CACHE)
else :
result = sched_get(datet, d.link,
datet.replace(day = 28, month = 1, year = datet.year + 1),
NO_CACHE)
# # Utilisation du module 'ics' pour le tri du calendrier dans l'ordre # # Utilisation du module 'ics' pour le tri du calendrier dans l'ordre
# # chronologique : # # chronologique :
# cal = ics.Calendar(result) # cal = ics.Calendar(result)
@ -417,4 +412,4 @@ def getrooms(datet, depts, ignore_list) :
dept_index += 1 dept_index += 1
return total_rooms return total_rooms

View File

@ -9,30 +9,29 @@ body {
background: var(--bg); background: var(--bg);
color: var(--fg); color: var(--fg);
font-family: "ubuntu", sans-serif; font-family: "ubuntu", sans-serif;
margin: 0px;
} }
h1, h2 { h1, h2 {
text-align: center; text-align: center;
font-size: 5vh; font-size: 6vh;
} }
h2 { h2 {
font-size: 4vh; font-size: 5vh;
font-weight: normal; font-weight: normal;
/* margin-bottom: 8vh; */ margin-bottom: 8vh;
} }
/* .slider { .slider { overflow: hidden;
overflow: hidden; }
} */
.slide-track { .slide-track {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: space-evenly; gap: 3vw;
gap: 2vw; animation: scroll 40s linear infinite;
/* animation: scroll 40s linear infinite; */ width: 3000vh; /* Pas bô, mais on va faire avec en attendant... */
/* width: 3000vh; Pas bô, mais on va faire avec en attendant... */
} }
.room { .room {
@ -43,26 +42,26 @@ h2 {
border-color: var(--bg-dark); border-color: var(--bg-dark);
border-radius: 3vw; border-radius: 3vw;
padding: 1vw; padding: 1vw;
height: 10vh; height: 17vh;
color: var(--bg); color: var(--bg);
font-size: 5vh; font-size: 8vh;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
} }
/* @keyframes scroll { @keyframes scroll {
0% { transform: translateX(0); } 0% { transform: translateX(0); }
100% { transform: translateX(calc(-25vw * 7)); } 100% { transform: translateX(calc(-25vw * 7)); }
} */ }
.details { .details {
margin: 1vh; margin: 1vh;
font-size: 4vh; font-size: 6vh;
} }
footer { footer {
margin-top: 5vh; margin-top: 8vh;
font-size: 3vh; font-size: 3vh;
text-align: center; text-align: center;
} }

View File

@ -13,16 +13,19 @@
<div class="slide-track"> <div class="slide-track">
{% if favs: %} {% if favs: %}
<!-- Afficher les favoris --> <!-- Afficher les favoris -->
{% if favs_free_rooms|length > 0 : %} <!-- Deux fois pour que l'animation boucle -->
{% for room in favs_free_rooms : %} {% for i in range(2) : %}
<div class="room"> {% if favs_free_rooms|length > 0 : %}
<b>{{ room.name }}</b> {% if DEBUG :%}( {{ room.id }} ){% endif %} {% for room in favs_free_rooms : %}
{% if not(room.noend) : %} <div class="room">
<p class=details>Jusqu'à {{ frooms_disp[room.name]["end"] }}</p> <b>{{ room.name }}</b> {% if DEBUG :%}( {{ room.id }} ){% endif %}
{% endif %} {% if not(room.noend) : %}
</div> <p class=details>Jusqu'à {{ frooms_disp[room.name]["end"] }}</p>
{% endfor %} {% endif %}
{% endif %} </div>
{% endfor %}
{% endif %}
{% endfor %}
{% else %} {% else %}
<!-- Si les favoris ne sont pas définis, afficher les salles classiques --> <!-- Si les favoris ne sont pas définis, afficher les salles classiques -->
{% for i in range(2):%} {% for i in range(2):%}