rsuinux

apod en fond d'écran sur lxde

Feb 10th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.55 KB | None | 0 0
  1. #!/bin/bash
  2. # -------------------------------------------------------------------------
  3. # R. Suinot <remi -at- suinot.org>
  4. # 25 Sept. 2012
  5. # rev. 10 fev. 2016
  6. # image en fond d'écran avec nitrogen renouvelable
  7. # tous les jours
  8. # Utilisation:
  9. # placer le script dans ~/bin/
  10. # chmod +x ~/bin/change_walpaper3.sh
  11. # installer la crontab sans oublier l'export du DISPLAY (à tester)
  12. # 0 * * * * export DISPLAY=:0.0 && ~/bin/change_walpaper3.sh
  13. # ou mettre un lien dans / etc/wicd/postconnect/
  14. # -------------------------------------------------------------------------
  15.  
  16. # chaque jour, une image nouvelle!
  17. # http://apod.nasa.gov/apod/ap120917.html
  18. # l'image est dans la page html la date est dans le nom de la page: 120917 -> 17 septembre 2012
  19.  
  20. cd /home/remi
  21. log="/tmp/mod-papier.txt"
  22. basenom=${0##*/}
  23. fichier_temporaire="/tmp/page_temporaire.html"
  24. dossier_images="/home/remi/Images/Wallpapers/"
  25. nom="desktop6.jpg"
  26. adresse="http://apod.nasa.gov/apod/"
  27. adresse_page="http://apod.nasa.gov/apod/ap"$(date +%y)$(date +%m)$(date +%d)".html"
  28. # adresse_page="http://apod.nasa.gov/apod/ap120917.html"
  29.  
  30. heure=$(date +%y)$(date +%m)$(date +%d)
  31.  
  32. wget $adresse_page -O $fichier_temporaire
  33. temp=$(stat -c%s $fichier_temporaire)
  34. if [[ $temp > 1000 ]]
  35. then
  36.   echo "[$basenom] $(date) -> $temp" >> $log
  37.   # j'ai récupéré la page du jour, il faut trouver l'image incluse dedans, à présent!
  38.   image_du_site=$( grep "IMG SRC" $fichier_temporaire | cut -d \" -f 2)
  39.   image_locale=$( cut -d / -f3 <<< $image_du_site)
  40.   if [[ $image_du_site =~ [*.jpg] ]]
  41.   then
  42.     adr_image=$adresse$image_du_site
  43.     echo "[$basenom]  +-> image= $adr_image." >> $log
  44.     echo "[$basenom]  +-> image source= $image_du_site." >> $log
  45.     echo "[$basenom]  +-> image destination= $image_locale." >> $log
  46.     cd $dossier_images
  47.     if [[ -e $image_locale ]]
  48.     then
  49.       echo "[$basenom]  $image_locale déjà changée" >> $log
  50.     else
  51.       echo "[$basenom] recuperation inage" >> $log
  52.       wget $adr_image -O $image_locale
  53.       temp=$(stat -c%s $image_locale)
  54.       echo "[$basenom]  +-> $temp" >> $log
  55.       if [[ $temp > 1000 ]]
  56.       then
  57.         rm $nom
  58.         mogrify -fill white -pointsize 16 -annotate +15+820 "$heure" $image_locale
  59.         rm $nom
  60.         ln -s $image_locale $nom
  61.         # cp $image_locale $nom
  62.       else
  63.         echo "[$basenom] Pas de nouvelle image" >> $log
  64.       fi
  65.     fi
  66.     rm $fichier_temporaire
  67.   else
  68.     echo "[$basenom] Image au mauvais format de fichier" >> $log
  69.   fi
  70. else
  71.   echo "[$basenom] Pas de nouvelle image" >> $log
  72. fi
  73. exit 0
Advertisement
Add Comment
Please, Sign In to add comment