Created
August 17, 2017 10:14
-
-
Save IanSmith123/b496cad832b7755dbee8e95acb3c1b2d to your computer and use it in GitHub Desktop.
download bing wall paper for recent 7 days
This file contains hidden or 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
import requests | |
sample_api_url = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1" | |
# notice: add a num after "idx=", this is the count of day before today | |
api_url = "http://www.bing.com/HPImageArchive.aspx?format=js&n=1&idx=" | |
def get_pic_url(num): | |
r = requests.get(api_url+repr(num)) | |
con = r.json() | |
pic_url = con['images'][0]['url'] | |
pic_intro = con['images'][0]['copyright'].split()[0] | |
print('\n') | |
print(pic_url) | |
print(pic_intro) | |
return 'http://www.bing.com'+pic_url, pic_intro | |
def download_pic(info): | |
pic_url = info[0] | |
pic_intro = info[1] | |
print('download', pic_intro) | |
r = requests.get(pic_url) | |
with open('pic/' + pic_intro + '.' + pic_url.split('.')[-1], 'wb') as f: | |
f.write(r.content) | |
f.close() | |
def wapper(num): | |
download_pic(get_pic_url(num)) | |
for i in range(8): | |
wapper(i) |
Author
IanSmith123
commented
Aug 17, 2017
This is what the api return.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment