-
Notifications
You must be signed in to change notification settings - Fork 0
/
APOD.py
35 lines (33 loc) · 968 Bytes
/
APOD.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import wget
import requests
import ast
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
import shutil
import os
url= "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY"
r = requests.get(url)
data = ast.literal_eval(r.content.decode('utf-8'))
try:
print(data["url"])
print(data["media_type"])
if data["media_type"] == "image":
wget.download(data["url"], "./APOD_temp.jpg")
# img = plt.imread("./APOD_temp.jpg")
# plt.imshow(img)
# plt.show()
picture_path = "./APOD_current.jpg"
shutil.move("./APOD_temp.jpg", picture_path)
rawpath = os.getcwd() + "/APOD_current.jpg"
path = rawpath.replace('\\', '/')
# ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0)
print(os.getcwd())
print(rawpath)
print(path)
print(picture_path)
else:
print("Content not an image!")
pass
except:
print("\nService unreachable!")