Last active
March 4, 2020 11:22
-
-
Save b00f/81fa7ee626ab4d43d2b24d7052b9465c to your computer and use it in GitHub Desktop.
National Geographic - Photo of the day -
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ng_json_url="https://www.nationalgeographic.com/photography/photo-of-the-day/_jcr_content/.gallery.json" | |
path="$HOME/Pictures/Wallpapers/" | |
mkdir -p $path | |
echo "Pinging NG API..." | |
# Fetching API response. | |
resp=$(curl -s $ng_json_url) | |
if [ $? -gt 0 ]; then | |
echo "Ping failed!" | |
exit 1 | |
fi | |
content=$(curl -s $ng_json_url) | |
image_caption=$(echo $content | jq -r '.items[0].image.caption') | |
image_url=$(echo $content | jq -r '.items[0].image.renditions[-1].uri') | |
image_name=$(echo $content | jq -r '.items[0].image.title') | |
image_name=${image_name// /_} | |
image_name=${image_name,,} | |
image_filename=${path}${image_name}".jpg" | |
echo ${image_url} | |
echo ${image_caption} | |
curl -s -o ${image_filename} $image_url | |
echo $image_caption > ${image_filename}".txt" | |
if [ "$XDG_CURRENT_DESKTOP" = "XFCE" ] | |
then | |
xres=($(echo $(xfconf-query --channel xfce4-desktop --list | grep last-image))) | |
for x in "${xres[@]}" | |
do | |
xfconf-query --channel xfce4-desktop --property $x --set ${image_filename} | |
done | |
# Set the wallpaper for unity, gnome3, cinnamon. | |
elif gsettings set org.gnome.desktop.background picture-uri "file://${image_filename}"; then | |
#Logging | |
# Set the view to zoom, | |
gsettings set org.gnome.desktop.background picture-options "zoom" | |
else | |
echo "$XDG_CURRENT_DESKTOP not supported." | |
break | |
fi | |
echo "New wallpaper set successfully for $XDG_CURRENT_DESKTOP." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment