From 8f0b57a3598f4116b69ea85f0ca7b9d7129f81e7 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 11 Mar 2022 11:50:18 -0800 Subject: [PATCH 1/3] Replace bitcoin demo with text only quote demo --- examples/magtag_bitcoin_demo.py | 37 -------------------- examples/magtag_quote_demo.py | 61 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 37 deletions(-) delete mode 100644 examples/magtag_bitcoin_demo.py create mode 100644 examples/magtag_quote_demo.py diff --git a/examples/magtag_bitcoin_demo.py b/examples/magtag_bitcoin_demo.py deleted file mode 100644 index 2bf7b3c..0000000 --- a/examples/magtag_bitcoin_demo.py +++ /dev/null @@ -1,37 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense -from adafruit_magtag.magtag import MagTag - -# Set up where we'll be fetching data from -DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json" -DATA_LOCATION = ["bpi", "USD", "rate_float"] - - -def text_transform(val): - return "Bitcoin: $%d" % val - - -magtag = MagTag( - url=DATA_SOURCE, - json_path=DATA_LOCATION, -) - -magtag.network.connect() - -magtag.add_text( - text_position=( - (magtag.graphics.display.width // 2) - 1, - (magtag.graphics.display.height // 2) - 1, - ), - text_scale=3, - text_transform=text_transform, - text_anchor_point=(0.5, 0.5), -) - -try: - value = magtag.fetch() - print("Response is", value) -except (ValueError, RuntimeError) as e: - print("Some error occured, retrying! -", e) -magtag.exit_and_deep_sleep(60) diff --git a/examples/magtag_quote_demo.py b/examples/magtag_quote_demo.py new file mode 100644 index 0000000..f4b8405 --- /dev/null +++ b/examples/magtag_quote_demo.py @@ -0,0 +1,61 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense +import os +import time +from adafruit_magtag.magtag import MagTag + +# Set up where we'll be fetching data from +DATA_SOURCE = "https://www.adafruit.com/api/quotes.php" +QUOTE_LOCATION = [0, "text"] +AUTHOR_LOCATION = [0, "author"] + +# the current working directory (where this file is) +try: + cwd = os.path.dirname(os.path.realpath(__file__)) +except AttributeError: + cwd = ("/" + __file__).rsplit("/", 1)[0] + +magtag = MagTag( + url=DATA_SOURCE, + json_path=(QUOTE_LOCATION, AUTHOR_LOCATION), + default_bg=0x000000, +) + +def add_quote_marks(quote_text): + return f"\"{quote_text}\"" + +def add_hyphen(author_name): + return f"- {author_name}" + +magtag.add_text( + text_position=( + (magtag.graphics.display.width // 2) - 1, + (magtag.graphics.display.height // 2) - 20, + ), + text_color=0xFFFFFF, + text_wrap=44, + text_maxlen=180, + line_spacing=1.0, + text_transform=add_quote_marks, + text_anchor_point=(0.5, 0.5), +) + +magtag.add_text( + text_position=( + (magtag.graphics.display.width // 2) - 120, + (magtag.graphics.display.height // 2) + 34, + ), + text_color=0xFFFFFF, + text_wrap=0, + text_maxlen=30, + text_transform=add_hyphen, +) + +while True: + try: + value = magtag.fetch() + print("Response is", value) + except (ValueError, RuntimeError) as e: + print("Some error occured, retrying! -", e) + time.sleep(180) \ No newline at end of file From 40fca18d3b090e77065e37fd602aad911c885416 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 11 Mar 2022 11:51:19 -0800 Subject: [PATCH 2/3] Ran pre-commit --- examples/magtag_quote_demo.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/magtag_quote_demo.py b/examples/magtag_quote_demo.py index f4b8405..5086b4c 100644 --- a/examples/magtag_quote_demo.py +++ b/examples/magtag_quote_demo.py @@ -22,12 +22,15 @@ default_bg=0x000000, ) + def add_quote_marks(quote_text): - return f"\"{quote_text}\"" + return f'"{quote_text}"' + def add_hyphen(author_name): return f"- {author_name}" + magtag.add_text( text_position=( (magtag.graphics.display.width // 2) - 1, @@ -58,4 +61,4 @@ def add_hyphen(author_name): print("Response is", value) except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) - time.sleep(180) \ No newline at end of file + time.sleep(180) From b6421ef427e50a573202b57b750490de815196bb Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 11 Mar 2022 12:01:28 -0800 Subject: [PATCH 3/3] Fix docs to point to new example --- docs/examples.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index 8805a84..c7b2206 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -10,6 +10,6 @@ Ensure your device works with this simple test. Other Demos ------------ -.. literalinclude:: ../examples/magtag_bitcoin_demo.py - :caption: examples/magtag_bitcoin_demo.py +.. literalinclude:: ../examples/magtag_quote_demo.py + :caption: examples/magtag_quote_demo.py :linenos: