Update wallpaper download jobs to be idempotent
This commit is contained in:
@ -5,63 +5,72 @@
|
|||||||
# Last Revised 22 May 2019
|
# Last Revised 22 May 2019
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
#Change directory to where the script resides.
|
# For feh, we need display set properly
|
||||||
export DISPLAY=:0.0
|
export DISPLAY=:0.0
|
||||||
BASEDIR="$HOME/var/inbox/ng_photos"
|
|
||||||
cd $BASEDIR
|
|
||||||
#######################
|
|
||||||
|
|
||||||
#getting the image URL
|
|
||||||
img="$(curl https://www.nationalgeographic.com/photography/photo-of-the-day/ -s | grep -oP '(?<="twitter:image:src" content=")\K[^"]*')"
|
|
||||||
|
|
||||||
#check to see if there is any wallpaper to download
|
|
||||||
if [ -n "$img" ]
|
|
||||||
then
|
|
||||||
img_base=`echo $img | cut -d/ -f 5`
|
|
||||||
img_md5=`echo -n $img_base | md5sum | cut -f1 -d" "`
|
|
||||||
img_file="$img_md5.jpg"
|
|
||||||
|
|
||||||
curl "$img" > $img_file
|
|
||||||
#set the current image as wallpaper
|
|
||||||
# feh --bg-scale $BASEDIR/$img_md5.jpg
|
|
||||||
# #link slim background to new image
|
|
||||||
# rm /usr/share/slim/themes/default/background.jpg
|
|
||||||
# ln -s $BASEDIR/$img_md5.jpg /usr/share/slim/themes/default/background.jpg
|
|
||||||
else
|
|
||||||
echo "No Wallpaper today"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Then grab our APOD image and store it for now
|
|
||||||
#Change directory to where the script resides.
|
|
||||||
BASEDIR="$HOME/var/inbox/apod_photos"
|
|
||||||
cd $BASEDIR
|
|
||||||
#######################
|
|
||||||
|
|
||||||
#getting the image URL
|
|
||||||
img="$(curl https://api.nasa.gov/planetary/apod\?api_key=AdfgdnmmInYgpDMEq3ShMLKjJ7DZ7jyUcgLHWdgw | jq .hdurl | tr -d \")"
|
|
||||||
|
|
||||||
#check to see if there is any wallpaper to download
|
|
||||||
if [ -n "$img" ]
|
|
||||||
then
|
|
||||||
img_file=`echo $img | cut -d/ -f 7 | tr -d \"`
|
|
||||||
curl $img > $img_file
|
|
||||||
#set the current image as wallpaper
|
|
||||||
#feh --bg-scale $BASEDIR/$img_file
|
|
||||||
##link slim background to new image
|
|
||||||
#rm /usr/share/slim/themes/default/background.jpg
|
|
||||||
#ln -s $BASEDIR/$img_file /usr/share/slim/themes/default/background.jpg
|
|
||||||
else
|
|
||||||
echo "No Wallpaper today"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Get daily Astrobin PotD
|
||||||
BASEDIR="$HOME/var/inbox/astrobin/"
|
BASEDIR="$HOME/var/inbox/astrobin/"
|
||||||
# use python script to get astrobin iotd
|
|
||||||
python3 ~/.bin/get_astrobin_potd.py
|
python3 ~/.bin/get_astrobin_potd.py
|
||||||
|
|
||||||
date=$(date '+%Y-%m-%d')
|
date=$(date '+%Y-%m-%d')
|
||||||
|
|
||||||
#set the current image as wallpaper
|
#set the current image as wallpaper
|
||||||
feh --bg-scale $BASEDIR/$date.jpg
|
feh --bg-scale $BASEDIR/$date.jpg
|
||||||
#link slim background to new image
|
#link slim background to new image
|
||||||
rm /usr/share/slim/themes/default/background.jpg
|
rm /usr/share/slim/themes/default/background.jpg
|
||||||
ln -s $BASEDIR/$date.jpg /usr/share/slim/themes/default/background.jpg
|
ln -s $BASEDIR/$date.jpg /usr/share/slim/themes/default/background.jpg
|
||||||
|
echo "Background and slim wallpaper set using Astrobin PotD"
|
||||||
|
|
||||||
|
|
||||||
|
####### OLD Picture fetching for NatGeo and NASA APoD
|
||||||
|
#######
|
||||||
|
|
||||||
|
|
||||||
|
#Change directory to where the script resides.
|
||||||
|
#BASEDIR="$HOME/var/inbox/ng_photos"
|
||||||
|
#cd $BASEDIR
|
||||||
|
#######################
|
||||||
|
|
||||||
|
#getting the image URL
|
||||||
|
#img="$(curl https://www.nationalgeographic.com/photography/photo-of-the-day/ -s | grep -oP '(?<="twitter:image:src" content=")\K[^"]*')"
|
||||||
|
#
|
||||||
|
## Check to see if there is any wallpaper to download
|
||||||
|
#if [ -n "$img" ]
|
||||||
|
#then
|
||||||
|
# img_base=`echo $img | cut -d/ -f 5`
|
||||||
|
# img_md5=`echo -n $img_base | md5sum | cut -f1 -d" "`
|
||||||
|
# img_file="$img_md5.jpg"
|
||||||
|
#
|
||||||
|
# curl "$img" > $img_file
|
||||||
|
# #set the current image as wallpaper
|
||||||
|
# #feh --bg-scale $BASEDIR/$img_md5.jpg
|
||||||
|
# ##link slim background to new image
|
||||||
|
# #rm /usr/share/slim/themes/default/background.jpg
|
||||||
|
# #ln -s $BASEDIR/$img_md5.jpg /usr/share/slim/themes/default/background.jpg
|
||||||
|
#else
|
||||||
|
# echo "No Wallpaper today"
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# Then grab our APOD image and store it for now
|
||||||
|
#Change directory to where the script resides.
|
||||||
|
#BASEDIR="$HOME/var/inbox/apod_photos"
|
||||||
|
#cd $BASEDIR
|
||||||
|
########################
|
||||||
|
#
|
||||||
|
## Get the APoD image from NASA
|
||||||
|
#img="$(curl https://api.nasa.gov/planetary/apod\?api_key=AdfgdnmmInYgpDMEq3ShMLKjJ7DZ7jyUcgLHWdgw | jq .hdurl | tr -d \")"
|
||||||
|
#
|
||||||
|
##check to see if there is any wallpaper to download
|
||||||
|
#if [ -n "$img" ]
|
||||||
|
#then
|
||||||
|
# img_file=`echo $img | cut -d/ -f 7 | tr -d \"`
|
||||||
|
# curl $img > $img_file
|
||||||
|
# #set the current image as wallpaper
|
||||||
|
# #feh --bg-scale $BASEDIR/$img_file
|
||||||
|
# ##link slim background to new image
|
||||||
|
# #rm /usr/share/slim/themes/default/background.jpg
|
||||||
|
# #ln -s $BASEDIR/$img_file /usr/share/slim/themes/default/background.jpg
|
||||||
|
#else
|
||||||
|
# echo "No Wallpaper today"
|
||||||
|
#fi
|
||||||
|
|||||||
@ -1,8 +1,17 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
today = datetime.today().strftime("%Y-%m-%d")
|
||||||
|
target_path = f"/home/powellc/var/inbox/astrobin/{today}.jpg"
|
||||||
|
|
||||||
|
# If the file for today already exists, just exit
|
||||||
|
if os.path.isfile(target_path):
|
||||||
|
print(f"Astrobin image for {today} already exists, skipping download")
|
||||||
|
exit()
|
||||||
|
|
||||||
root = "https://www.astrobin.com"
|
root = "https://www.astrobin.com"
|
||||||
api_key = "3f542cbb23407bde6f20490f377366582dd1a54c"
|
api_key = "3f542cbb23407bde6f20490f377366582dd1a54c"
|
||||||
api_secret = (
|
api_secret = (
|
||||||
@ -20,9 +29,6 @@ r = requests.get(
|
|||||||
image_uri = r.json()["url_real"]
|
image_uri = r.json()["url_real"]
|
||||||
img = requests.get(image_uri, stream=True)
|
img = requests.get(image_uri, stream=True)
|
||||||
|
|
||||||
today = datetime.today().strftime("%Y-%m-%d")
|
|
||||||
target_path = f"/home/powellc/var/inbox/astrobin/{today}.jpg"
|
|
||||||
|
|
||||||
handle = open(target_path, "wb")
|
handle = open(target_path, "wb")
|
||||||
for chunk in img.iter_content(chunk_size=512):
|
for chunk in img.iter_content(chunk_size=512):
|
||||||
if chunk: # filter out keep-alive new chunks
|
if chunk: # filter out keep-alive new chunks
|
||||||
|
|||||||
@ -9,9 +9,9 @@ prefs:
|
|||||||
maxHistories: 2
|
maxHistories: 2
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
WallpaperUpdate:
|
CheckForNewWallpaper:
|
||||||
cmd: /home/powellc/.bin/changepaper.sh
|
cmd: /home/powellc/.bin/changepaper.sh
|
||||||
time: 0 0 10
|
time: 0 */30
|
||||||
onError: Stop
|
onError: Stop
|
||||||
notifyOnFailure:
|
notifyOnFailure:
|
||||||
- *filesystemSink
|
- *filesystemSink
|
||||||
|
|||||||
Reference in New Issue
Block a user