Skip to content

Commit 780933a

Browse files
committed
CMA Art Frame: initial commit
1 parent 22a06d2 commit 780933a

File tree

5 files changed

+14437
-0
lines changed

5 files changed

+14437
-0
lines changed

PyPortal_CMA_Art_Frame/background.bmp

225 KB
Binary file not shown.
450 KB
Binary file not shown.

PyPortal_CMA_Art_Frame/code.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import time
2+
import random
3+
import board
4+
from adafruit_pyportal import PyPortal
5+
from adafruit_display_shapes.circle import Circle
6+
7+
WIDTH = board.DISPLAY.width
8+
HEIGHT = board.DISPLAY.height
9+
10+
#pylint: disable=line-too-long
11+
12+
# these lines show the entire collection
13+
APIURL = "https://openaccess-api.clevelandart.org/api/artworks?cc0=1&has_image=1&indent=2&limit=1&skip="
14+
IMAGECOUNT = 31954
15+
16+
# uncomment these lines to show just paintings
17+
# APIURL = "https://openaccess-api.clevelandart.org/api/artworks?cc0=1&has_image=1&indent=2&limit=1&type=Painting&skip="
18+
# IMAGECOUNT = 3223
19+
20+
BACKGROUND_FILE = "/background.bmp"
21+
if WIDTH > 320:
22+
BACKGROUND_FILE = "/background_480.bmp"
23+
24+
pyportal = PyPortal(default_bg=BACKGROUND_FILE,
25+
image_json_path=["data", 0, "images", "web", "url"],
26+
image_dim_json_path=(["data", 0, "images", "web", "width"],
27+
["data", 0, "images", "web", "height"]),
28+
image_resize=(WIDTH, HEIGHT - 15),
29+
image_position=(0, 0),
30+
text_font="/fonts/OpenSans-9.bdf",
31+
json_path=["data", 0, "title"],
32+
text_position=(4, HEIGHT - 9),
33+
text_color=0xFFFFFF)
34+
35+
circle = Circle(312, 233, 5, fill=0)
36+
pyportal.splash.append(circle)
37+
loopcount = 0
38+
errorcount = 0
39+
while True:
40+
response = None
41+
try:
42+
circle.fill = 0xFF0000
43+
itemid = random.randint(1, IMAGECOUNT)
44+
# itemid = 20 # portrait mode example
45+
# itemid = 21 # landscape mode example
46+
print("retrieving url:", APIURL + str(itemid))
47+
response = pyportal.fetch(APIURL + str(itemid))
48+
circle.fill = 0
49+
print("Response is", response)
50+
loopcount = loopcount + 1
51+
52+
except (RuntimeError, KeyError) as e:
53+
print("An error occured, retrying! -", e)
54+
print("loop counter:", loopcount)
55+
assert errorcount < 20, "Too many errors, stopping"
56+
errorcount = errorcount + 1
57+
time.sleep(60)
58+
continue
59+
60+
errorcount = 0
61+
stamp = time.monotonic()
62+
# wait 5 minutes before getting again
63+
while (time.monotonic() - stamp) < (5*60):
64+
# or, if they touch the screen, fetch immediately!
65+
if pyportal.touchscreen.touch_point:
66+
break

0 commit comments

Comments
 (0)