Add astrobin image downloader
This commit is contained in:
@ -22,10 +22,10 @@ then
|
|||||||
|
|
||||||
curl "$img" > $img_file
|
curl "$img" > $img_file
|
||||||
#set the current image as wallpaper
|
#set the current image as wallpaper
|
||||||
feh --bg-scale $BASEDIR/$img_md5.jpg
|
# feh --bg-scale $BASEDIR/$img_md5.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/$img_md5.jpg /usr/share/slim/themes/default/background.jpg
|
# ln -s $BASEDIR/$img_md5.jpg /usr/share/slim/themes/default/background.jpg
|
||||||
else
|
else
|
||||||
echo "No Wallpaper today"
|
echo "No Wallpaper today"
|
||||||
fi
|
fi
|
||||||
@ -52,3 +52,15 @@ then
|
|||||||
else
|
else
|
||||||
echo "No Wallpaper today"
|
echo "No Wallpaper today"
|
||||||
fi
|
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
|
||||||
|
|||||||
27
systemd/.config/systemd/user/get_astrobin_potd.py
Executable file
27
systemd/.config/systemd/user/get_astrobin_potd.py
Executable 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)
|
||||||
Reference in New Issue
Block a user