This repository has been archived by the owner on May 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
64 lines (56 loc) · 2.3 KB
/
main.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
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
61
62
63
64
import platform
import os
import urllib.request
import time
import ctypes
import traceback
import sys
__title__ = 'Unsplash Wallpaper'
__version__ = "1.2"
__author__ = 'tobimori'
# last edited @ 22.10.2018
def get_screensize(multiplier):
try:
user32 = ctypes.windll.user32
screensize = f"{user32.GetSystemMetrics(78)*multiplier}x{user32.GetSystemMetrics(79)*multiplier}"
print(f"\r[+] Status: Detected virtual monitor size {user32.GetSystemMetrics(78)}x{user32.GetSystemMetrics(79)}.", end="")
if multiplier > 1:
print(f"\r[+] Status: Multiplying to {screensize} for better quality.", end="")
return screensize
except:
print(f"\r[-] Status: Encountered some problems while detecting your display size.", end="")
traceback.print_exc()
sys.exit(1)
def get_image(multiplier):
directory = os.getcwd() + "/.unsplash"
if not os.path.exists(directory):
os.makedirs(directory)
print("\r[+] Status: Create temporary directory", end="")
filepath = directory + "/" + str(time.time()) + ".jpg"
print(f"\r[+] Status: Starting download...", end="")
try:
screensize = get_screensize(multiplier)
urllib.request.urlretrieve("https://source.unsplash.com/random/" + screensize, filepath)
print(f"\r[+] Status: Downloaded image from source.unsplash.com/random/{screensize} to {filepath}", end="")
return filepath
except:
print(f"\r[-] Status: Encountered some problems while downloading the image.", end="")
traceback.print_exc()
sys.exit(1)
print(f"\033[32m{__title__} v{__version__} by {__author__}\n")
print("\033[0m")
osvar = platform.system()
if osvar == "Windows":
print("\r[+] Status: Detected System: Windows", end="")
print("\033[33m\nWell, I hate Windows, but it was the easiest thing to implement, so let's do this!\n")
print("\033[0m")
filepath_absolute = get_image(2)
try:
ctypes.windll.user32.SystemParametersInfoW(20, 0, filepath_absolute, 0)
print("\n[+] Status: Done!", end="")
except:
print(f"\r[-] Status: Error - Couldn't set your wallpaper.", end="")
traceback.print_exc()
sys.exit(1)
else:
print("\r[-] Status: Sorry, only supporting Windows right now. Feel free to fork and add support ;)", end="")