-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwin-runner.py
More file actions
51 lines (41 loc) · 1.05 KB
/
win-runner.py
File metadata and controls
51 lines (41 loc) · 1.05 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
import time
from bingimage import getBingImage
from settings import BING_CHINA
import sys
_ver = sys.version_info
py3_or_upper = (_ver[0] > 2)
def setWallpaperWithBingImage():
if py3_or_upper == False:
return -1
if sys.platform != "win32":
return -1
imgData = getBingImage(BING_CHINA)
if imgData == None:
return -1
import tempfile
fp = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False)
if fp == None:
return -1
fp.write(imgData)
tmp_name = fp.name
fp.close()
fp = None
import ctypes
SPI_SETDESKWALLPAPER = 20
SPIF_UPDATEINIFILE = 1
SPIF_SENDCHANGE = 2
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, tmp_name, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE)
import os
os.remove(tmp_name)
print("Set wallpaper successful.")
return 0
if __name__=="__main__":
res = 0
i = 0
while i < 6:
res = setWallpaperWithBingImage()
if res == 0:
break
time.sleep(2)
i += 1
sys.exit(res)