Skip to content

Instantly share code, notes, and snippets.

@curipha
Created October 24, 2021 06:09
Show Gist options
  • Save curipha/5d1053d14dae8dad1dc03f5cbd4a2528 to your computer and use it in GitHub Desktop.
Save curipha/5d1053d14dae8dad1dc03f5cbd4a2528 to your computer and use it in GitHub Desktop.
Download bing wallpaper
#!/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