Guest User

Wallpaper change

a guest
May 8th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. import requests
  2. import ctypes
  3. import datetime
  4. import time
  5. from datetime import date
  6.  
  7.  
  8. SPI_SETDESKWALLPAPER = 20
  9. path_to_folder = r"C:\Users\Simon\Documents\Folders\Photos\Backgrounds\Python"
  10.  
  11. api_address='http://api.openweathermap.org/data/2.5/weather?appid=0c42f7f6b53b244c78a418f4f181282a&q='
  12. city = "WHERE YOU LIVE"
  13.  
  14. url = api_address + city
  15.  
  16.  
  17. def main():
  18.     timestamp = datetime.datetime.now().time()
  19.     start_night = datetime.time(18, 1)
  20.     end_night = datetime.time(6, 0)
  21.     start_day = datetime.time(6, 1)
  22.     end_day = datetime.time(18, 0)
  23.     json_data = requests.get(url).json()
  24.     format_data = json_data["weather"][0]["main"]
  25.     print("Looped")
  26.  
  27.     if date.today().weekday() == 6:
  28.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Tokyo.jpg", 3)
  29.         print("Sunday")
  30.     if format_data == "Rain":
  31.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Waterfall.jpg", 3)
  32.         print("Rain")
  33.     elif format_data == "Thunderstorm":
  34.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Cloud.jpg", 3)
  35.         print("Storm")
  36.     elif format_data == "Drizzle":
  37.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Rooftop1.png", 3)
  38.         print("Drizzle")
  39.  
  40. # Night & Day
  41.     elif format_data == "Clear" and start_night <= timestamp or timestamp <= end_night:
  42.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Moon.png", 3)
  43.         print("Night")
  44.     elif format_data == "Clear" and start_day <= timestamp <= end_day:
  45.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\KatanaMorning.png", 3)
  46.         print("Day")
  47.  
  48.     elif format_data == "Clouds":
  49.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Shibuya.png", 3)
  50.         print("Clouds")
  51.     else:
  52.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Firewatch.jpg", 3)
  53.         print("Other")
  54.  
  55.  
  56. if __name__ == '__main__':
  57.     while True:
  58.         main()
  59.         time.sleep(120)
Add Comment
Please, Sign In to add comment