Add bing and unsplash to wallpaper script

This commit is contained in:
Colin Powell
2020-02-18 13:56:43 -05:00
parent 0f720be71f
commit ee7b92dc41
3 changed files with 53 additions and 2 deletions

24
bin/.bin/get_unsplash_potd.py Executable file
View File

@ -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)