Add astrobin image downloader

This commit is contained in:
Colin Powell
2019-12-04 23:13:59 -05:00
parent 71ad3aa36d
commit 3bbc7f6bb8
2 changed files with 47 additions and 8 deletions

View File

@ -16,16 +16,16 @@ img="$(curl https://www.nationalgeographic.com/photography/photo-of-the-day/ -s
#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_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
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
@ -52,3 +52,15 @@ then
else
echo "No Wallpaper today"
fi
BASEDIR="$HOME/var/inbox/astrobin/"
# use python script to get astrobin iotd
./get_astrobin_potd.py
date=$(date '+%Y-%m-%d')
#set the current image as wallpaper
feh --bg-scale $BASEDIR/$date.jpg
#link slim background to new image
rm /usr/share/slim/themes/default/background.jpg
ln -s $BASEDIR/$date.jpg /usr/share/slim/themes/default/background.jpg

View File

@ -0,0 +1,27 @@
#!/usr/bin/env python3
from datetime import datetime
import requests
import subprocess
root = "https://www.astrobin.com"
api_key = "3f542cbb23407bde6f20490f377366582dd1a54c"
api_secret = subprocess.check_output(
"pass personal/apikey/astrobin", shell=True
).decode("utf-8").strip()
fmt = "json"
iotd_uri = f"{root}/api/v1/imageoftheday/?limit=1&api_key={api_key}&api_secret={api_secret}&format={fmt}"
r = requests.get(iotd_uri)
image_info_uri = r.json()["objects"][0]["image"]
r = requests.get(
f"{root}{image_info_uri}?api_key={api_key}&api_secret={api_secret}&format={fmt}"
)
image_uri = r.json()["url_real"]
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")
for chunk in img.iter_content(chunk_size=512):
if chunk: # filter out keep-alive new chunks
handle.write(chunk)