Guest User

Untitled

a guest
May 23rd, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. http://www.bing.com/az/hprichbg/rb/EuropeESA_DE-DE7849418832_1920x1080.jpg
  2. http://www.bing.com/az/hprichbg/rb/CanisLupus_DE-DE11366975292_1920x1080.jpg
  3. http://www.bing.com/az/hprichbg/rb/HouseBoats_DE-DE8695714746_1920x1080.jpg
  4.  
  5. for number, url in enumerate(list_of_urls):
  6. urllib.urlretrieve(url, 'Image {}.jpg'.format(number + 1))
  7.  
  8. import requests
  9. import json
  10.  
  11. BING_URI_BASE = "http://www.bing.com"
  12. BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"
  13.  
  14. # open the Bing HPImageArchive URI and ask for a JSON response
  15. resp = requests.get(BING_URI_BASE + BING_WALLPAPER_PATH)
  16.  
  17. if resp.status_code == 200:
  18. json_response = json.loads(resp.content)
  19. wallpaper_path = json_response['images'][0]['url']
  20. filename = wallpaper_path.split('/')[-1]
  21. wallpaper_uri = BING_URI_BASE + wallpaper_path
  22.  
  23. # open the actual wallpaper uri, and write the response as an image on the filesystem
  24. response = requests.get(wallpaper_uri)
  25. if resp.status_code == 200:
  26. with open(filename, 'wb') as f:
  27. f.write(response.content)
  28. else:
  29. raise ValueError("[ERROR] non-200 response from Bing server for '{}'".format(wallpaper_uri))
  30. else:
  31. raise ValueError("[ERROR] non-200 response from Bing server for '{}'".format(BING_URI_BASE + BING_WALLPAPER_PATH))
Add Comment
Please, Sign In to add comment