From ee7b92dc412f1e94fc6033216f7630bbc2146364 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Tue, 18 Feb 2020 13:56:43 -0500 Subject: [PATCH] Add bing and unsplash to wallpaper script --- bin/.bin/changepaper.sh | 6 ++++-- bin/.bin/get_bing_potd.py | 25 +++++++++++++++++++++++++ bin/.bin/get_unsplash_potd.py | 24 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100755 bin/.bin/get_bing_potd.py create mode 100755 bin/.bin/get_unsplash_potd.py diff --git a/bin/.bin/changepaper.sh b/bin/.bin/changepaper.sh index 54ed7b8..b049744 100755 --- a/bin/.bin/changepaper.sh +++ b/bin/.bin/changepaper.sh @@ -9,13 +9,15 @@ export DISPLAY=:0.0 export XAUTHORITY=/home/powellc/.Xauthority -# Choices: astrobin,natgeo,nasa -BASEDIR="$HOME/var/backgrounds/astrobin/" +# Choices: astrobin,natgeo,nasa,unsplash +BASEDIR="$HOME/var/backgrounds/unsplash/" SEARX_BASEDIR="$HOME/var/backgrounds/natgeo/" # Get daily NatGeo POTD python3 ~/.bin/get_natgeo_potd.py python3 ~/.bin/get_astrobin_potd.py +python3 ~/.bin/get_unsplash_potd.py +python3 ~/.bin/get_bing_potd.py date=$(date '+%Y-%m-%d') diff --git a/bin/.bin/get_bing_potd.py b/bin/.bin/get_bing_potd.py new file mode 100755 index 0000000..b6305a3 --- /dev/null +++ b/bin/.bin/get_bing_potd.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import os +import subprocess +from datetime import datetime + +import requests + +today = datetime.today().strftime("%Y-%m-%d") +home = os.path.expanduser("~") +target_path = f"{home}/var/backgrounds/bing/{today}.jpg" + +# If the file for today already exists, just exit +if os.path.isfile(target_path): + print(f"Bing image for {today} already exists, skipping download") + exit() + +iotd_uri = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=1&n=1" +r = requests.get(iotd_uri) +image_info_uri = r.json()["images"][0]["url"] +img = requests.get(f"https://www.bing.com{image_info_uri}", 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) diff --git a/bin/.bin/get_unsplash_potd.py b/bin/.bin/get_unsplash_potd.py new file mode 100755 index 0000000..e658c16 --- /dev/null +++ b/bin/.bin/get_unsplash_potd.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import os +import subprocess +from datetime import datetime + +import requests + +today = datetime.today().strftime("%Y-%m-%d") +home = os.path.expanduser("~") +target_path = f"{home}/var/backgrounds/unsplash/{today}.jpg" + +# If the file for today already exists, just exit +if os.path.isfile(target_path): + print(f"Unsplash image for {today} already exists, skipping download") + exit() + +root = "https://source.unsplash.com" +iotd_uri = f"{root}/random/daily" +img = requests.get(iotd_uri, 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)