Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import ctypes
- import datetime
- import time
- from datetime import date
- SPI_SETDESKWALLPAPER = 20
- path_to_folder = r"C:\Users\Simon\Documents\Folders\Photos\Backgrounds\Python"
- api_address='http://api.openweathermap.org/data/2.5/weather?appid=0c42f7f6b53b244c78a418f4f181282a&q='
- city = "WHERE YOU LIVE"
- url = api_address + city
- def main():
- timestamp = datetime.datetime.now().time()
- start_night = datetime.time(18, 1)
- end_night = datetime.time(6, 0)
- start_day = datetime.time(6, 1)
- end_day = datetime.time(18, 0)
- json_data = requests.get(url).json()
- format_data = json_data["weather"][0]["main"]
- print("Looped")
- if date.today().weekday() == 6:
- ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Tokyo.jpg", 3)
- print("Sunday")
- if format_data == "Rain":
- ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Waterfall.jpg", 3)
- print("Rain")
- elif format_data == "Thunderstorm":
- ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Cloud.jpg", 3)
- print("Storm")
- elif format_data == "Drizzle":
- ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Rooftop1.png", 3)
- print("Drizzle")
- # Night & Day
- elif format_data == "Clear" and start_night <= timestamp or timestamp <= end_night:
- ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Moon.png", 3)
- print("Night")
- elif format_data == "Clear" and start_day <= timestamp <= end_day:
- ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\KatanaMorning.png", 3)
- print("Day")
- elif format_data == "Clouds":
- ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Shibuya.png", 3)
- print("Clouds")
- else:
- ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_folder + "\Firewatch.jpg", 3)
- print("Other")
- if __name__ == '__main__':
- while True:
- main()
- time.sleep(120)
Add Comment
Please, Sign In to add comment