-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapod_wallpaper_setter.py
More file actions
60 lines (49 loc) · 1.99 KB
/
apod_wallpaper_setter.py
File metadata and controls
60 lines (49 loc) · 1.99 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from logging import error
import wallpaper_utility
from win10toast import ToastNotifier
from random import choice
from apod_object_parser import download_image, get_data, get_data_array, get_date, get_hdurl, get_media_type, get_url, is_connected
# NASA Astronomical Picture of the Day API Key. "DEMO_KEY" value works too but with 30 requests per hour
# still since we update our wallpaper less frequently we need not worry about the key
def startSetWallpaperProcedure():
response = get_data(wallpaper_utility.APOD_API_KEY)
print(response)
url = get_url(response)
media_type = get_media_type(response)
if media_type == "image":
try:
# best case, we'll get a hd walpaper for the day.
hd_url = get_hdurl(response)
except:
hd_url = getOneWorkingImageFromArchive()
else:
hd_url = getOneWorkingImageFromArchive()
wallpaper_image_path = download_image(hd_url,get_date(response))
print(wallpaper_image_path)
wallpaper_utility.changeBG(wallpaper_image_path)
n.show_toast(wallpaper_utility.SERVICE_NAME, "Wallpaper changed!", duration = 10)
def getOneWorkingImageFromArchive():
responses_array = get_data_array(wallpaper_utility.APOD_API_KEY)
print("checking archives:")
archive_responses_list = []
print(responses_array)
for res in responses_array:
try:
hd_url = get_hdurl(res)
archive_responses_list.append(hd_url)
except:
pass
if len(archive_responses_list) == 0 :
n.show_toast(wallpaper_utility.SERVICE_NAME, "Archive retrieval failed", duration = 10)
return error
else :
return choice(archive_responses_list)
n = ToastNotifier()
if __name__ == "__main__":
print("Program Started")
if not is_connected() :
print("Internet Not Connected")
n.show_toast(wallpaper_utility.SERVICE_NAME, "Internet not connected")
else:
print("Internet is connected")
startSetWallpaperProcedure()