Created
October 24, 2021 06:09
-
-
Save curipha/5d1053d14dae8dad1dc03f5cbd4a2528 to your computer and use it in GitHub Desktop.
Download bing wallpaper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import hashlib | |
from urllib import request,parse | |
BING_URI = 'https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1' | |
req = request.urlopen(BING_URI) | |
bing = json.loads(req.read()) | |
image = parse.urljoin('https://www.bing.com/', bing['images'][0]['url']) | |
print(image) | |
req = request.urlopen(image) | |
with open('./{0}.jpg'.format(hashlib.sha256(image.encode()).hexdigest()), 'wb') as fp: | |
fp.write(req.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment