Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # -------------------------------------------------------------------------
- # R. Suinot <remi -at- suinot.org>
- # 25 Sept. 2012
- # rev. 10 fev. 2016
- # image en fond d'écran avec nitrogen renouvelable
- # tous les jours
- # Utilisation:
- # placer le script dans ~/bin/
- # chmod +x ~/bin/change_walpaper3.sh
- # installer la crontab sans oublier l'export du DISPLAY (à tester)
- # 0 * * * * export DISPLAY=:0.0 && ~/bin/change_walpaper3.sh
- # ou mettre un lien dans / etc/wicd/postconnect/
- # -------------------------------------------------------------------------
- # chaque jour, une image nouvelle!
- # http://apod.nasa.gov/apod/ap120917.html
- # l'image est dans la page html la date est dans le nom de la page: 120917 -> 17 septembre 2012
- cd /home/remi
- log="/tmp/mod-papier.txt"
- basenom=${0##*/}
- fichier_temporaire="/tmp/page_temporaire.html"
- dossier_images="/home/remi/Images/Wallpapers/"
- nom="desktop6.jpg"
- adresse="http://apod.nasa.gov/apod/"
- adresse_page="http://apod.nasa.gov/apod/ap"$(date +%y)$(date +%m)$(date +%d)".html"
- # adresse_page="http://apod.nasa.gov/apod/ap120917.html"
- heure=$(date +%y)$(date +%m)$(date +%d)
- wget $adresse_page -O $fichier_temporaire
- temp=$(stat -c%s $fichier_temporaire)
- if [[ $temp > 1000 ]]
- then
- echo "[$basenom] $(date) -> $temp" >> $log
- # j'ai récupéré la page du jour, il faut trouver l'image incluse dedans, à présent!
- image_du_site=$( grep "IMG SRC" $fichier_temporaire | cut -d \" -f 2)
- image_locale=$( cut -d / -f3 <<< $image_du_site)
- if [[ $image_du_site =~ [*.jpg] ]]
- then
- adr_image=$adresse$image_du_site
- echo "[$basenom] +-> image= $adr_image." >> $log
- echo "[$basenom] +-> image source= $image_du_site." >> $log
- echo "[$basenom] +-> image destination= $image_locale." >> $log
- cd $dossier_images
- if [[ -e $image_locale ]]
- then
- echo "[$basenom] $image_locale déjà changée" >> $log
- else
- echo "[$basenom] recuperation inage" >> $log
- wget $adr_image -O $image_locale
- temp=$(stat -c%s $image_locale)
- echo "[$basenom] +-> $temp" >> $log
- if [[ $temp > 1000 ]]
- then
- rm $nom
- mogrify -fill white -pointsize 16 -annotate +15+820 "$heure" $image_locale
- rm $nom
- ln -s $image_locale $nom
- # cp $image_locale $nom
- else
- echo "[$basenom] Pas de nouvelle image" >> $log
- fi
- fi
- rm $fichier_temporaire
- else
- echo "[$basenom] Image au mauvais format de fichier" >> $log
- fi
- else
- echo "[$basenom] Pas de nouvelle image" >> $log
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment