Update wallpaper download jobs to be idempotent

This commit is contained in:
Colin Powell
2020-01-21 08:31:59 -05:00
parent 164bfebb83
commit 59f843b8bd
3 changed files with 68 additions and 53 deletions

View File

@ -1,8 +1,17 @@
#!/usr/bin/env python3
import os
from datetime import datetime
import requests
import subprocess
today = datetime.today().strftime("%Y-%m-%d")
target_path = f"/home/powellc/var/inbox/astrobin/{today}.jpg"
# If the file for today already exists, just exit
if os.path.isfile(target_path):
print(f"Astrobin image for {today} already exists, skipping download")
exit()
root = "https://www.astrobin.com"
api_key = "3f542cbb23407bde6f20490f377366582dd1a54c"
api_secret = (
@ -20,9 +29,6 @@ r = requests.get(
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