Created
June 5, 2019 07:15
-
-
Save vwillcox/0fc0b0e71d708b0c05df807cd5cc8916 to your computer and use it in GitHub Desktop.
Get Nasa AOD and set as a Windows desktop image, also send a notification with image title and description. Thanks to Big Les (https://bigl.es/tooling-tuesday-nasa-api-and-python/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
import ctypes | |
from win10toast import ToastNotifier | |
url = "https://api.nasa.gov/planetary/apod?api_key=" | |
os.environ['NO_PROXY'] = 'nasa.gov' | |
r = requests.get(url) | |
toaster = ToastNotifier() | |
if r: | |
APOD = r.json()['hdurl'] | |
title = r.json()['title'] | |
detail = r.json()['explanation'] | |
pic = requests.get(APOD, allow_redirects=True) | |
if "jpg" not in APOD: | |
print("No image") | |
else: | |
open('C:\\Users\\vincent.willcox\\Pictures\\APOD.jpg', 'wb').write(pic.content) | |
ctypes.windll.user32.SystemParametersInfoW(20, 0, "C:\\Users\\vincent.willcox\\Pictures\\APOD.jpg" , 0) | |
toaster.show_toast(title, detail, icon_path=None, duration=10, threaded=True) | |
print("DONE") | |
else: | |
print("Error") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment