30 lines
943 B
Python
Executable File
30 lines
943 B
Python
Executable File
#!/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)
|