From 95bc313658e487a2ea3b319d1752debf2607574b Mon Sep 17 00:00:00 2001 From: tfa Date: Thu, 5 Oct 2023 15:00:16 +0200 Subject: [PATCH] Ajout script --- fip.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 fip.sh diff --git a/fip.sh b/fip.sh new file mode 100644 index 0000000..ff9dc44 --- /dev/null +++ b/fip.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +colors=("31" "32" "33" "34" "35" "36" "37") +color_index=0 + +function get_next_color() { + local current_color_index="$1" + local next_color_index=$(( (current_color_index + 1) % ${#colors[@]} )) + echo "$next_color_index" +} + +function print_data() { + local json_data="$1" + local output="" + IFS=$'\n' + for item in $(echo "$json_data" | jq -c '.[]'); do + slug=$(echo "$item" | jq -r '.slug') + titre=$(echo "$item" | jq -r '.now.firstLine') + artiste=$(echo "$item" | jq -r '.now.secondLine') + + slug=${slug#fip_} + slug="$(tr '[:lower:]' '[:upper:]' <<< ${slug:0:1})${slug:1}" + + + color_code=${colors[$color_index]} + slug="\033[1;${color_code}m$slug\033[0m" + + slug=$(printf "%-32s" "$slug") + artiste=$(printf "%-40s" "$artiste") + titre=$(printf "%-40s" "$titre") + output+="\033[1$slug\033[0m | \033[1mArtiste:\033[0m $artiste | \033[1mTitre:\033[0m $titre |\n" + color_index=$(get_next_color "$color_index") + done + clear + echo -e "$output" +} + + +md5="" +while true; do + # Exécuter la commande curl pour obtenir les données JSON + json_data=$(curl -s "https://www.radiofrance.fr/fip/api/webradios?station=fip") + + # Calculer le hachage MD5 des données JSON actuelles + new_md5=$(echo -n "$json_data" | md5sum | awk '{print $1}') + + # Vérifier si le hachage MD5 a changé (c'est-à-dire si les données ont changé) + if [ "$new_md5" != "$md5" ]; then + # Afficher les données en utilisant la fonction print_data + print_data "$json_data" + md5="$new_md5" + fi + + # Attendre 5 secondes avant la prochaine requête curl + sleep 5 +done \ No newline at end of file