Ajout script
This commit is contained in:
56
fip.sh
Normal file
56
fip.sh
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user