U:horaires.sh
This commit is contained in:
parent
f1bfff1d71
commit
926927d0c4
2 changed files with 36 additions and 33 deletions
|
@ -1,13 +1,13 @@
|
|||
Jour,Semaine,Horaire
|
||||
Lundi,A,09:00-14:00
|
||||
Mardi,A,07:00-12:00 12:30-17:00
|
||||
Mercredi,A,12:30-18:00
|
||||
Jeudi,A,07:00-12:00 13:30-17:00
|
||||
Vendredi,A,08:30-12:30 13:30-18:00
|
||||
Lundi,B,09:00-15:00
|
||||
Mardi,B,07:00-12:00 12:30-17:00
|
||||
Mercredi,B,14:00-17:00
|
||||
Jeudi,B,07:00-13:00
|
||||
Vendredi,B,07:00-12:00 14:00-18:00
|
||||
Samedi,B,08:00-12:00
|
||||
Lundi,A,09:00-14:00
|
||||
Mardi,A,07:00-12:00 12:30-17:00
|
||||
Mercredi,A,12:30-18:00
|
||||
Jeudi,A,07:00-12:00 13:30-17:00
|
||||
Vendredi,A,08:30-12:30 13:30-18:00
|
||||
|
||||
|
|
|
|
@ -1,7 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Fichier CSV contenant les horaires
|
||||
CSV_FILE="horaires.csv"
|
||||
# --- Gestion du fichier CSV ---
|
||||
if [[ -f "$1" ]]; then
|
||||
CSV_FILE="$1"
|
||||
shift
|
||||
else
|
||||
CSV_FILE="./horaires.csv"
|
||||
fi
|
||||
|
||||
# Traduction manuelle des jours (anglais -> français)
|
||||
declare -A JOURS_EN_FR=(
|
||||
|
@ -14,46 +19,44 @@ declare -A JOURS_EN_FR=(
|
|||
["Sunday"]="Dimanche"
|
||||
)
|
||||
|
||||
# Liste des jours en français pour correspondre aux numéros (1 = Lundi, ...)
|
||||
# Liste des jours en français (1 = Lundi, ...)
|
||||
JOURS=("Lundi" "Mardi" "Mercredi" "Jeudi" "Vendredi" "Samedi" "Dimanche")
|
||||
|
||||
# Si l'argument est un chiffre (1 ou 2), on calcule le jour futur
|
||||
if [[ "$1" =~ ^[1-2]$ ]]; then
|
||||
# Calculer la date future
|
||||
DATE_FUTURE=$(date -d "+$1 day" +"%A") # Ex: "Sunday"
|
||||
JOUR=${JOURS_EN_FR[$DATE_FUTURE]} # Traduction
|
||||
|
||||
# Vérifier si on change de semaine
|
||||
SEMAINE_NUM=$(date -d "+$1 day" +"%V")
|
||||
if ((SEMAINE_NUM % 2 == 0)); then
|
||||
SEMAINE="A"
|
||||
# --- Fonction pour normaliser le jour ---
|
||||
normalize_day() {
|
||||
local jour=$1
|
||||
if [[ -n "${JOURS_EN_FR[$jour]}" ]]; then
|
||||
# Jour anglais → traduction
|
||||
echo "${JOURS_EN_FR[$jour]}"
|
||||
else
|
||||
SEMAINE="B"
|
||||
# Jour français → on force Majuscule initiale
|
||||
echo "${jour^}"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Détermination du jour/semaine ---
|
||||
if [[ "$1" =~ ^[1-2]$ ]]; then
|
||||
JOUR_RAW=$(date -d "+$1 day" +"%A")
|
||||
JOUR=$(normalize_day "$JOUR_RAW")
|
||||
SEMAINE_NUM=$(date -d "+$1 day" +"%V")
|
||||
((SEMAINE_NUM % 2 == 0)) && SEMAINE="A" || SEMAINE="B"
|
||||
|
||||
# Sinon, si l'argument est du type "3B"
|
||||
elif [[ "$1" =~ ^[1-7][AB]$ ]]; then
|
||||
JOUR_INDEX=${1:0:1} # Numéro du jour (1 = Lundi, ..., 7 = Dimanche)
|
||||
SEMAINE=${1:1:1} # A ou B
|
||||
|
||||
JOUR_INDEX=${1:0:1}
|
||||
SEMAINE=${1:1:1}
|
||||
JOUR=${JOURS[$((JOUR_INDEX - 1))]}
|
||||
|
||||
# Sinon, on prend le jour actuel
|
||||
else
|
||||
JOUR_ANGLAIS=$(date +"%A")
|
||||
JOUR=${JOURS_EN_FR[$JOUR_ANGLAIS]} # Traduction
|
||||
JOUR_RAW=$(date +"%A")
|
||||
JOUR=$(normalize_day "$JOUR_RAW")
|
||||
SEMAINE_NUM=$(date +"%V")
|
||||
if ((SEMAINE_NUM % 2 == 0)); then
|
||||
SEMAINE="A"
|
||||
else
|
||||
SEMAINE="B"
|
||||
fi
|
||||
((SEMAINE_NUM % 2 == 0)) && SEMAINE="A" || SEMAINE="B"
|
||||
fi
|
||||
|
||||
# Lire et filtrer le CSV
|
||||
# --- Lecture du CSV ---
|
||||
HORAIRE=$(awk -F, -v jour="$JOUR" -v semaine="$SEMAINE" '$1 == jour && $2 == semaine {print $3}' "$CSV_FILE")
|
||||
|
||||
# Afficher le résultat
|
||||
# --- Résultat ---
|
||||
if [[ -n "$HORAIRE" ]]; then
|
||||
echo "Horaires de $JOUR (semaine $SEMAINE) : $HORAIRE"
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue