Git Product home page Git Product logo

vesta's Introduction

Vesta

Vesta is a Vestaboard client library for Python. It provides API clients and character encoding utilities.

Installation

Vesta requires Python 3.8 or later. It can be installed via PyPI:

$ python -m pip install vesta

Its only runtime dependency is the HTTPX library, which will be installed automatically.

Usage

API Clients

Read / Write API

ReadWriteClient provides a client interface for interacting with a Vestaboard using the Read / Write API.

Note that Vestaboard owners must first obtain their Read / Write API key by enabling the Vestaboard's Read / Write API via the Settings section of the mobile app or from the Developer section of the web app.

import vesta
rw_client = vesta.ReadWriteClient("read_write_key")

# Once enabled, you can write and read messages:
message = vesta.encode_text("{67} Hello, World {68}")
assert rw_client.write_message(message)
assert rw_client.read_message() == message

Subscription API

SubscriptionClient provides a client interface for interacting with multiple Vestaboards using the Subscription API.

Note that an API secret and key is required to get subscriptions or send messages. These credentials can be created from the Developer section of the web app.

Messages can be posted as either text strings or two-dimensional arrays of character codes representing the exact positions of characters on the board.

If text is specified, the lines will be centered horizontally and vertically. Character codes will be inferred for alphanumeric and punctuation characters, or they can be explicitly specified using curly braces containing the character code (such as {5} or {65}).

import vesta
subscription_client = vesta.SubscriptionClient("api_key", "api_secret")

# List subscriptions and send them messages:
subscriptions = subscription_client.get_subscriptions()
for subscription in subscriptions:
    subscription_client.send_message(subscription["id"], "{67} Hello, World {68}")

Local API

LocalClient provides a client interface for interacting with a Vestaboard over the local network using Vestaboard's Local API.

Note that Vestaboard owners must first request a Local API enablement token in order to use the Local API.

import vesta
local_client = vesta.LocalClient()

# The Vestaboard's Local API must be enabled to get its Local API key. After
# you've done this once, you can save the key somewhere safe and pass it
# directly to LocalClient() for future client initializations.
local_api_key = local_client.enable(ENABLEMENT_TOKEN)
# e.g. local_client = LocalClient(local_api_key)
assert local_client.enabled

# Once enabled, you can write and read messages:
message = vesta.encode_text("{67} Hello, World {68}")
assert local_client.write_message(message)
assert local_client.read_message() == message

VBML API

VBMLClient provides a client interface for Vestaboard's VBML (Vestaboard Markup Language) API.

import vesta

component = Component(
    "Vestaboard Markup Language",
    justify="center",
    align="center",
    width=22,
    height=6,
)

vbml_client = vesta.VBMLClient()
vesta.pprint(vbml_client.compose([component]))

Platform Client

Client provides a client interface for interacting with the deprecated Vestaboard Platform API.

This is the original Vestaboard Platform API. It is deprecated and has been superseded by the other APIs listed above. In particular, Vestaboard encourages users of the Platform API to switch to the Subscription API, which offers nearly identical functionality.

Character Encoding

All Vestaboard characters (letters, numbers, symbols, and colors) are encoded as integer character codes. Vesta includes some useful routines for working with these character codes.

encode() encodes a string as a list of character codes. In addition to printable characters, the string can contain character code sequences inside curly braces, such as {5} or {65}.

>>> vesta.encode("{67} Hello, World {68}")
[67, 0, 8, 5, 12, 12, 15, 55, 0, 23, 15, 18, 12, 4, 0, 68]

encode_row() encodes a string as a row of character codes. It builds on encode() by providing alignment control.

>>> vesta.encode_row("{67} Hello, World {68}", align="center")
[0, 0, 0, 67, 0, 8, 5, 12, 12, 15, 55, 0, 23, 15, 18, 12, 4, 0, 68, 0, 0, 0]

encode_text() encodes a string of text into rows of character codes, further building on encode() and encode_row() with the addition of alignment, margin control, and line breaks.

>>> encode_text("multiple\nlines\nof\ntext", align="center", valign="middle")
[
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 13, 21, 12, 20, 9, 16, 12, 5, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 12, 9, 14, 5, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 5, 24, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
]

Lastly, pprint() can be used to pretty-print encoded characters to the console, which can be useful during development.

>>> vesta.pprint([0, 0, 0, 67, 0, 8, 5, 12, 12, 15, 55, 0, 23, 15, 18, 12, 4, 0, 68, 0, 0, 0])
| | | |◼︎| |H|E|L|L|O|,| |W|O|R|L|D| |◼︎| | | |

Examples

License

This project is licensed under the terms of the MIT license.

vesta's People

Contributors

dependabot[bot] avatar jparise avatar natekspencer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

natekspencer

vesta's Issues

Bug posting encoded text?

Hi,

Thanks for this library. I've got it working fine for text messages, but it seems to fail when posting any encoded text - my board just goes blank. I did some experimenting and I think the bug is that it is improperly flagging a passed in list of encoded characters as text. Observe the following output noting that it thinks it is a text message in both scenarios:

>>> result = vclient.post_message(config.VESTA_SUBSCRIPTION_ID, "foo")
>>> print(result)
{'message': {'id': 'ce7915b1-20fb-4cf9-bfca-0ac6c911b20f', 'text': 'foo', 'created': '1639946986010'}}

>>> result = vclient.post_message(config.VESTA_SUBSCRIPTION_ID, [[0, 0, 0, 0, 0, 0, 0, 13, 21, 12, 20, 9, 16, 12, 5, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 12, 9, 14, 5, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 5, 24, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> print(result)
{'message': {'id': '8ebe9257-6827-4d8e-8d11-b65b2a81cfec', 'text': None, 'created': '1639947016428'}}

Am I doing something wrong? Many thanks!

Feature request: Return truncated rows from encoded_text instead of raising an error

Right now, when encode_text is called with data that results in a number of rows greater than 6, a ValueError is raised. It would be nice if, instead, this could log a warning, and then return only the first 6 rows. This would be useful for truncating long song names while also trying to append a header or footer without introducing more complex logic.

Example code produces an error

The example code in the README for local access includes these two lines

message = vesta.encode("{67} Hello, World {68}")
assert local_client.write_message(message)

However, data produced by vesta.encode apparently does not meet the format required by local_client.write_message and produces this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.9/site-packages/vesta/clients.py", line 222, in write_message
    validate_rows(message)
  File "/opt/homebrew/lib/python3.9/site-packages/vesta/chars.py", line 52, in validate_rows
    raise ValueError(f"expected a ({ROWS}, {COLS}) array of encoded characters")
ValueError: expected a (6, 22) array of encoded characters

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.