Skip to content

Instantly share code, notes, and snippets.

@marks
Last active December 10, 2022 06:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marks/a3c5bbe851495e6c4616aea3834cca2c to your computer and use it in GitHub Desktop.
Save marks/a3c5bbe851495e6c4616aea3834cca2c to your computer and use it in GitHub Desktop.
Update your @Vestaboard via command line

Down below is a quick script that lets you update your Vestaboard from the command line using curl and `jq

Try a rainbow:

bash vestaboard.sh " \
{63}{64}{65}{66}{67}{68} All \n \
{63}{64}{65}{66}{67}{68} You \n \
{63}{64}{65}{66}{67}{68} Need \n \
{63}{64}{65}{66}{67}{68} Is \n \
{63}{64}{65}{66}{67}{68} Love \n \
{63}{64}{65}{66}{67}{68}"

Tweet w/ video

# Assumes curl and jq are installed
##################################
# REQUIRED INPUT: API key/secret #
##################################
# Retrieve from https://web.vestaboard.com; API docs at https://docs.vestaboard.com
VESTABOARD_API_KEY=""
VESTABOARD_API_SECRET=""
###########################
# Input/message detection #
###########################
# Detect input string; if empty, assign a generic message with the current date
VESTABOARD_TEXT_TO_SEND=$1
if [ -z "$VESTABOARD_TEXT_TO_SEND" ]
then
VESTABOARD_TEXT_TO_SEND="Hello. It is currently $(date)."
echo "== Note about script invocation =="
echo "You did not provide an argument to this script so we will assign the following default input value:"
echo " $VESTABOARD_TEXT_TO_SEND"
echo
echo "Next time, define your own message by invoking the script like this:"
echo " bash $0 \"Hello from the command line!\""
echo
fi
#############
# Functions #
#############
# Helper function to call an arbitrary HTTP GET endpoint of Vestaboard API
function vestboard_api_call_get {
local ENDPOINT=$1
local URL="https://platform.vestaboard.com$ENDPOINT"
local API_CALL_RESPONSE=$(curl -s \
-H "X-Vestaboard-Api-Key: $VESTABOARD_API_KEY" \
-H "X-Vestaboard-Api-Secret: $VESTABOARD_API_SECRET" \
"$URL")
echo $API_CALL_RESPONSE
}
# Helper function to call an arbitrary HTTP POST endpoint of Vestaboard API
function vestboard_api_call_post {
local ENDPOINT=$1
local BODY=$2
local URL="https://platform.vestaboard.com$ENDPOINT"
local API_CALL_RESPONSE=$(curl -s \
-X POST \
-H "X-Vestaboard-Api-Key: $VESTABOARD_API_KEY" \
-H "X-Vestaboard-Api-Secret: $VESTABOARD_API_SECRET" \
-d "$BODY" \
$URL)
echo $API_CALL_RESPONSE
}
# Get the API key/secret's viewer info and echo it out
function viewer_info {
echo "== Vestaboard Viewer == "
VESTABOARD_VIEWER=$(vestboard_api_call_get "/viewer")
echo $VESTABOARD_VIEWER | jq
echo
}
# Publish a message to a subscription and report the API output
function publish_message {
echo "== Publish message to Subscription =="
local SUBSCRIPTION_ID=$1
local MESSAGE=$2
VESTABOARD_PUBISH_BODY="{\"text\":\"$MESSAGE\"}" # properly escape JSON
echo "Sending the following message to publish:"
echo $VESTABOARD_PUBISH_BODY | jq
echo
VESTABOARD_PUBLISH_RESPONSE=$(vestboard_api_call_post "/subscriptions/$SUBSCRIPTION_ID/message" "$VESTABOARD_PUBISH_BODY")
echo "Vestaboard API response was:"
echo $VESTABOARD_PUBLISH_RESPONSE | jq
echo
}
####################
# Script execution #
####################
viewer_info
# Get a list of subscriptions
echo "== Vestboard Subscription ID == "
VESTABOARD_SUBSCRIPTIONS=$(vestboard_api_call_get "/subscriptions")
# Pick out the first subscription and echo it out
echo "(While the API supports multiple subscriptions, this script simply selects the first)"
VESTABOARD_FIRST_SUBSCRIPTION_ID=$(echo $VESTABOARD_SUBSCRIPTIONS | jq -r '.subscriptions[0]._id')
echo \"$VESTABOARD_FIRST_SUBSCRIPTION_ID\" | jq
echo
publish_message "$VESTABOARD_FIRST_SUBSCRIPTION_ID" "$VESTABOARD_TEXT_TO_SEND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment