wallhaven.py 687 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python
  2. import requests
  3. # Try and get 1920x1080. Set this to True if you want that. You will
  4. # get images by having this turned on.
  5. high=False
  6. search = input("Wallhaven search: ")
  7. data = requests.get(f"https://wallhaven.cc/api/v1/search?q={search}").json()
  8. num = 0
  9. for i, wallpaper in enumerate(data["data"]):
  10. url = wallpaper["path"]
  11. if wallpaper["resolution"] == "1920x1080" and high == True:
  12. num = num+1
  13. file = f"{num}.{url.split('.')[3]}"
  14. print(url)
  15. print(file)
  16. else:
  17. file = f"{i}.{url.split('.')[3]}"
  18. print(url)
  19. print(file)
  20. with open(file,"wb") as f:
  21. f.write(requests.get(url).content)