/ PyPortal_Cutefuzz / code.py
code.py
1 # SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 import board 7 from adafruit_pyportal import PyPortal 8 9 # Set up where we'll be fetching data from, we have a few different 10 # cute animal services for cats, dogs and foxes! 11 12 # random cat 13 #DATA_SOURCE = "https://api.thecatapi.com/v1/images/search" 14 #IMAGE_LOCATION = [0, "url"] 15 16 # random fox 17 #DATA_SOURCE = "https://randomfox.ca/floof/" 18 #IMAGE_LOCATION = ["image"] 19 20 # random shibe 21 DATA_SOURCE = "http://shibe.online/api/shibes?count=1" 22 IMAGE_LOCATION = [0] 23 24 # determine the current working directory needed so we know where to find files 25 cwd = ("/"+__file__).rsplit('/', 1)[0] 26 pyportal = PyPortal(url=DATA_SOURCE, 27 status_neopixel=board.NEOPIXEL, 28 default_bg=cwd+"/cute_background.bmp", 29 image_json_path=IMAGE_LOCATION, 30 image_resize=(320, 240), 31 image_position=(0, 0)) 32 33 while True: 34 response = None 35 try: 36 response = pyportal.fetch() 37 print("Response is", response) 38 except RuntimeError as e: 39 print("Some error occured, retrying! -", e) 40 continue 41 42 stamp = time.monotonic() 43 # wait 5 minutes before getting again 44 while (time.monotonic() - stamp) < (5*60): 45 # or, if they touch the screen, fetch immediately! 46 if pyportal.touchscreen.touch_point: 47 break