Add better background setting scripts
This commit is contained in:
@ -9,9 +9,11 @@
|
|||||||
export DISPLAY=:0.0
|
export DISPLAY=:0.0
|
||||||
export XAUTHORITY=/home/powellc/.Xauthority
|
export XAUTHORITY=/home/powellc/.Xauthority
|
||||||
|
|
||||||
|
# Choices: astrobin,natgeo,nasa
|
||||||
|
BASEDIR="$HOME/var/backgrounds/natgeo/"
|
||||||
|
|
||||||
# Get daily Astrobin PotD
|
# Get daily NatGeo POTD
|
||||||
BASEDIR="$HOME/var/inbox/astrobin/"
|
python3 ~/.bin/get_natgeo_potd.py
|
||||||
python3 ~/.bin/get_astrobin_potd.py
|
python3 ~/.bin/get_astrobin_potd.py
|
||||||
|
|
||||||
date=$(date '+%Y-%m-%d')
|
date=$(date '+%Y-%m-%d')
|
||||||
@ -24,35 +26,6 @@ ln -s $BASEDIR/$date.jpg /usr/share/slim/themes/default/background.jpg
|
|||||||
echo "Background and slim wallpaper set using Astrobin PotD"
|
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
|
# Then grab our APOD image and store it for now
|
||||||
#Change directory to where the script resides.
|
#Change directory to where the script resides.
|
||||||
#BASEDIR="$HOME/var/inbox/apod_photos"
|
#BASEDIR="$HOME/var/inbox/apod_photos"
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
|
||||||
import requests
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
today = datetime.today().strftime("%Y-%m-%d")
|
today = datetime.today().strftime("%Y-%m-%d")
|
||||||
target_path = f"/home/powellc/var/inbox/astrobin/{today}.jpg"
|
home = os.path.expanduser("~")
|
||||||
|
target_path = f"{home}/var/backgrounds/astrobin/{today}.jpg"
|
||||||
|
|
||||||
# If the file for today already exists, just exit
|
# If the file for today already exists, just exit
|
||||||
if os.path.isfile(target_path):
|
if os.path.isfile(target_path):
|
||||||
|
|||||||
34
bin/.bin/get_natgeo_potd.py
Executable file
34
bin/.bin/get_natgeo_potd.py
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
today = datetime.today().strftime("%Y-%m-%d")
|
||||||
|
home = os.path.expanduser("~")
|
||||||
|
target_path = f"{home}/var/backgrounds/natgeo/{today}.jpg"
|
||||||
|
|
||||||
|
# If the file for today already exists, just exit
|
||||||
|
if os.path.isfile(target_path):
|
||||||
|
print(f"NatGeo image for {today} already exists, skipping download")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# We've got to go rummaging for:
|
||||||
|
# <meta name="twitter:image:src" content="<full_image_path">
|
||||||
|
potd_uri = "https://www.nationalgeographic.com/photography/photo-of-the-day/"
|
||||||
|
html_doc = requests.get(potd_uri).content
|
||||||
|
soup = BeautifulSoup(html_doc, "html.parser")
|
||||||
|
|
||||||
|
twitter_image_tag = soup.select('meta[name="twitter:image:src"]')[0]
|
||||||
|
|
||||||
|
image_tag = twitter_image_tag
|
||||||
|
img = requests.get(image_tag.attrs["content"], stream=True)
|
||||||
|
|
||||||
|
handle = open(target_path, "wb")
|
||||||
|
for chunk in img.iter_content(chunk_size=512):
|
||||||
|
if chunk: # filter out keep-alive new chunks
|
||||||
|
handle.write(chunk)
|
||||||
|
except: # noqa
|
||||||
|
print("No new NatGeo image for today, sorry.")
|
||||||
Reference in New Issue
Block a user