Skip to content

Instantly share code, notes, and snippets.

@YtvwlD
Last active June 30, 2018 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YtvwlD/4a12bb90cfaeea2195790d1a0a44f408 to your computer and use it in GitHub Desktop.
Save YtvwlD/4a12bb90cfaeea2195790d1a0a44f408 to your computer and use it in GitHub Desktop.
download NASA's Astronomy Picture of the Day
#!/usr/bin/env python3
from os import environ, rename
from os.path import expanduser
from urllib.request import urlretrieve
from bowshock.apod import apod
# you might want to change these values
DEST_FILE = expanduser("~/.cache/kscreenlocker_greet/plasma_engine_potd/apod")
NASA_API_KEY = "DEMO_KEY"
print("Moving old image...")
rename(DEST_FILE, DEST_FILE + ".bak")
environ["NASA_API_KEY"] = NASA_API_KEY
metadata = apod().json()
print("Downloading image...")
urlretrieve(metadata["url"], filename=DEST_FILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment