Skip to content

Commit a188c77

Browse files
authored
Merge pull request #81 from makermelissa/main
Replace bitcoin demo with text only quote demo
2 parents 6fd190b + b6421ef commit a188c77

File tree

3 files changed

+66
-39
lines changed

3 files changed

+66
-39
lines changed

docs/examples.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Ensure your device works with this simple test.
1010
Other Demos
1111
------------
1212

13-
.. literalinclude:: ../examples/magtag_bitcoin_demo.py
14-
:caption: examples/magtag_bitcoin_demo.py
13+
.. literalinclude:: ../examples/magtag_quote_demo.py
14+
:caption: examples/magtag_quote_demo.py
1515
:linenos:

examples/magtag_bitcoin_demo.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

examples/magtag_quote_demo.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
import os
5+
import time
6+
from adafruit_magtag.magtag import MagTag
7+
8+
# Set up where we'll be fetching data from
9+
DATA_SOURCE = "https://www.adafruit.com/api/quotes.php"
10+
QUOTE_LOCATION = [0, "text"]
11+
AUTHOR_LOCATION = [0, "author"]
12+
13+
# the current working directory (where this file is)
14+
try:
15+
cwd = os.path.dirname(os.path.realpath(__file__))
16+
except AttributeError:
17+
cwd = ("/" + __file__).rsplit("/", 1)[0]
18+
19+
magtag = MagTag(
20+
url=DATA_SOURCE,
21+
json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
22+
default_bg=0x000000,
23+
)
24+
25+
26+
def add_quote_marks(quote_text):
27+
return f'"{quote_text}"'
28+
29+
30+
def add_hyphen(author_name):
31+
return f"- {author_name}"
32+
33+
34+
magtag.add_text(
35+
text_position=(
36+
(magtag.graphics.display.width // 2) - 1,
37+
(magtag.graphics.display.height // 2) - 20,
38+
),
39+
text_color=0xFFFFFF,
40+
text_wrap=44,
41+
text_maxlen=180,
42+
line_spacing=1.0,
43+
text_transform=add_quote_marks,
44+
text_anchor_point=(0.5, 0.5),
45+
)
46+
47+
magtag.add_text(
48+
text_position=(
49+
(magtag.graphics.display.width // 2) - 120,
50+
(magtag.graphics.display.height // 2) + 34,
51+
),
52+
text_color=0xFFFFFF,
53+
text_wrap=0,
54+
text_maxlen=30,
55+
text_transform=add_hyphen,
56+
)
57+
58+
while True:
59+
try:
60+
value = magtag.fetch()
61+
print("Response is", value)
62+
except (ValueError, RuntimeError) as e:
63+
print("Some error occured, retrying! -", e)
64+
time.sleep(180)

0 commit comments

Comments
 (0)