Skip to content

Commit

Permalink
wallpaper.jpg will be left
Browse files Browse the repository at this point in the history
  • Loading branch information
kqakqakqa authored Oct 18, 2023
1 parent 208c14c commit 23623dc
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions wallpaper-only-once.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
import os
import time
import urllib.request
import sys


def wallpaper():
# get url
print("getting url:")
archive = urllib.request.urlopen("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN").read()
archiveJson = json.loads(archive)
imageUrl = "https://www.bing.com" + archiveJson["images"][0]["url"]
imageUrl = imageUrl.replace("1920x1080", "UHD")
print(imageUrl + "\n")

# get path
imagePath = os.path.dirname(os.path.abspath(__file__)) + "/bg.jpg"
print("getting path:")
imagePath = os.path.dirname(os.path.realpath(sys.argv[0])) + "\\wallpaper.jpg"
if os.path.exists(imagePath):
os.remove(imagePath)
print(imagePath + "\n")

# download
print("downloading")
urllib.request.urlretrieve(imageUrl, imagePath)

# set
print("setting")
SPI_SETDESKWALLPAPER = 0x0014
SPIF_UPDATEINIFILE = 0x0001
SPIF_SENDWININICHANGE = 0x0002
Expand All @@ -33,7 +36,9 @@ def wallpaper():
while trialLeft > 0:
try:
wallpaper()
print("done")
break
except:
print("retrying")
trialLeft -= 1
time.sleep(5)

0 comments on commit 23623dc

Please sign in to comment.