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
|
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
|
Lundi,B,09:00-15:00
|
||||||
Mardi,B,07:00-12:00 12:30-17:00
|
Mardi,B,07:00-12:00 12:30-17:00
|
||||||
Mercredi,B,14:00-17:00
|
Mercredi,B,14:00-17:00
|
||||||
Jeudi,B,07:00-13:00
|
Jeudi,B,07:00-13:00
|
||||||
Vendredi,B,07:00-12:00 14:00-18:00
|
Vendredi,B,07:00-12:00 14:00-18:00
|
||||||
Samedi,B,08:00-12: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
|
#!/bin/bash
|
||||||
|
|
||||||
# Fichier CSV contenant les horaires
|
# --- Gestion du fichier CSV ---
|
||||||
CSV_FILE="horaires.csv"
|
if [[ -f "$1" ]]; then
|
||||||
|
CSV_FILE="$1"
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
CSV_FILE="./horaires.csv"
|
||||||
|
fi
|
||||||
|
|
||||||
# Traduction manuelle des jours (anglais -> français)
|
# Traduction manuelle des jours (anglais -> français)
|
||||||
declare -A JOURS_EN_FR=(
|
declare -A JOURS_EN_FR=(
|
||||||
|
@ -14,46 +19,44 @@ declare -A JOURS_EN_FR=(
|
||||||
["Sunday"]="Dimanche"
|
["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")
|
JOURS=("Lundi" "Mardi" "Mercredi" "Jeudi" "Vendredi" "Samedi" "Dimanche")
|
||||||
|
|
||||||
# Si l'argument est un chiffre (1 ou 2), on calcule le jour futur
|
# --- Fonction pour normaliser le jour ---
|
||||||
if [[ "$1" =~ ^[1-2]$ ]]; then
|
normalize_day() {
|
||||||
# Calculer la date future
|
local jour=$1
|
||||||
DATE_FUTURE=$(date -d "+$1 day" +"%A") # Ex: "Sunday"
|
if [[ -n "${JOURS_EN_FR[$jour]}" ]]; then
|
||||||
JOUR=${JOURS_EN_FR[$DATE_FUTURE]} # Traduction
|
# Jour anglais → traduction
|
||||||
|
echo "${JOURS_EN_FR[$jour]}"
|
||||||
# Vérifier si on change de semaine
|
|
||||||
SEMAINE_NUM=$(date -d "+$1 day" +"%V")
|
|
||||||
if ((SEMAINE_NUM % 2 == 0)); then
|
|
||||||
SEMAINE="A"
|
|
||||||
else
|
else
|
||||||
SEMAINE="B"
|
# Jour français → on force Majuscule initiale
|
||||||
|
echo "${jour^}"
|
||||||
fi
|
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
|
elif [[ "$1" =~ ^[1-7][AB]$ ]]; then
|
||||||
JOUR_INDEX=${1:0:1} # Numéro du jour (1 = Lundi, ..., 7 = Dimanche)
|
JOUR_INDEX=${1:0:1}
|
||||||
SEMAINE=${1:1:1} # A ou B
|
SEMAINE=${1:1:1}
|
||||||
|
|
||||||
JOUR=${JOURS[$((JOUR_INDEX - 1))]}
|
JOUR=${JOURS[$((JOUR_INDEX - 1))]}
|
||||||
|
|
||||||
# Sinon, on prend le jour actuel
|
|
||||||
else
|
else
|
||||||
JOUR_ANGLAIS=$(date +"%A")
|
JOUR_RAW=$(date +"%A")
|
||||||
JOUR=${JOURS_EN_FR[$JOUR_ANGLAIS]} # Traduction
|
JOUR=$(normalize_day "$JOUR_RAW")
|
||||||
SEMAINE_NUM=$(date +"%V")
|
SEMAINE_NUM=$(date +"%V")
|
||||||
if ((SEMAINE_NUM % 2 == 0)); then
|
((SEMAINE_NUM % 2 == 0)) && SEMAINE="A" || SEMAINE="B"
|
||||||
SEMAINE="A"
|
|
||||||
else
|
|
||||||
SEMAINE="B"
|
|
||||||
fi
|
|
||||||
fi
|
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")
|
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
|
if [[ -n "$HORAIRE" ]]; then
|
||||||
echo "Horaires de $JOUR (semaine $SEMAINE) : $HORAIRE"
|
echo "Horaires de $JOUR (semaine $SEMAINE) : $HORAIRE"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue