Last active
October 19, 2017 18:47
-
-
Save dnewber/6e67ae4979d7707e9b769608189e9316 to your computer and use it in GitHub Desktop.
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 ctypes | |
| import time | |
| import shutil | |
| import requests | |
| def set_desktop(): | |
| SPI_SETDESKTOPWALLPAPER = 20 | |
| try: | |
| ctypes.windll.user32.SystemParametersInfoA( | |
| SPI_SETDESKTOPWALLPAPER, 0, 'inspirobot.jpg', 0) | |
| except Exception as e: | |
| print 'Something went wrong. ', e | |
| def get_image(): | |
| inspirobot_url = 'http://inspirobot.me/api?generate=true' | |
| image = requests.get(inspirobot_url).text | |
| return image | |
| def update_local_image(image_url): | |
| with open('inspirobot.jpg', 'wb') as fp: | |
| raw_image = requests.get(image_url, stream=True).raw | |
| raw_image.decode_content = True | |
| shutil.copyfileobj(raw_image, fp) | |
| def main(): | |
| while True: | |
| new_image = get_image() | |
| update_local_image(new_image) | |
| set_desktop() | |
| time.sleep(minute=15 * 60) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment