diff --git a/.github/workflows/wodaboard.yaml b/.github/workflows/wodaboard.yaml index 209fd17..3ed1348 100644 --- a/.github/workflows/wodaboard.yaml +++ b/.github/workflows/wodaboard.yaml @@ -22,4 +22,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VB_SUB_ID: ${{ secrets.VB_SUB_ID }} VB_SUB_KEY: ${{ secrets.VB_SUB_KEY }} - VB_SUB_SECRET: ${{ secrets.VB_SUB_SECRET }} \ No newline at end of file + VB_SUB_SECRET: ${{ secrets.VB_SUB_SECRET }} + MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} diff --git a/README.md b/README.md index fa9b857..b2a10b0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,33 @@ -# wodaboard -💪 "Workout Of the Day" on Vestaboard +# 💪 WODaboard 🏋️ +"Workout Of the Day" sent to a Vestaboard. This is an example of how you can use the Vestaboard developer API to send messages to your Vestaboard. +This Github Action workflow also posts the message to [workoutoftheday@mastodon.social](https://mastodon.social/@workoutoftheday). + +⚠️ Disclaimer: These workouts are random and vary in intensity. I am not a personal trainer, so seek professional advice before following my dummy data. + +# Create your own Vestaboard Installable/Subscription + +Use the web app's API tab to create an installable for your Vestaboard. +Once you have the subscription id, api key, and api secret, add them to your .env for running locally +or your GitHub action secrets for running with a GitHub workflow as a cron job. Be sure to keep your API keys secret and not commit them. + +``` +# .env +VB_SUB_ID=yoursubscriptionid +VB_SUB_KEY=yoursubscriptionapikey +VB_SUB_SECRET=yoursubscriptionapisecret + +# (optional to post to Mastodon) +MASTODON_ACCESS_TOKEN= ``` + +``` +# send a WOD to your Vestaboard +bun install bun run index.ts -``` \ No newline at end of file +``` + +You can find more information on Vestaboard subscriptions at https://docs.vestaboard.com. Happy hacking! + +[Issue with delay on GitHub actions during peak traffic times](https://github.com/orgs/community/discussions/52477) diff --git a/bun.lockb b/bun.lockb index 7c1b196..69863e7 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.ts b/index.ts index ffa9021..64e0f3b 100644 --- a/index.ts +++ b/index.ts @@ -3,7 +3,6 @@ import * as dotenv from "dotenv"; import { randomFourExercises } from "./plan"; dotenv.config(); export const API_URL = "https://platform.vestaboard.com"; -const intensity = "easy"; const days = { 0: "sunday", @@ -13,18 +12,31 @@ const days = { 4: "thursday", 5: "friday", 6: "saturday", -} as { [key: number]: IDays }; -type IDays = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday"; +} as { [key: number]: Days }; +type Days = + | "sunday" + | "monday" + | "tuesday" + | "wednesday" + | "thursday" + | "friday" + | "saturday"; -const main = () => { +type Intensity = "easy" | "medium" | "hard"; +// hardcode to easy for now +const intensity = "easy" as Intensity + +const main = async () => { const day = new Date().getDay(); const dayName = days[day]; - // const intensity = day % 3 === 0 ? "hard" : day % 2 === 0 ? "medium" : "easy"; + // const intensity = day % 3 === 1 ? "hard" : day % 3 === 2 ? "medium" : "easy"; const exercises = randomFourExercises(intensity); - const color = day % 3 === 0 ? "{63}" : day % 2 === 0 ? "{65}" : "{66}"; + const color = + intensity === "hard" ? "{63}" : intensity === "medium" ? "{65}" : "{66}"; const text = `${color}Happy ${dayName}!${color}\nToday's WOD is:\n${exercises}`; console.log(text); - sendMessage(text); + await sendMessage(text); + await sendMastodonMessage(text); }; const sendMessage = async (text: string) => { @@ -42,4 +54,25 @@ const sendMessage = async (text: string) => { } }; +const sendMastodonMessage = async (text: string) => { + const status = text + .replace("{66}", "🟩 ") + .replace("{66}", " 🟩") + .replace("{65}", "🟨 ") + .replace("{65}", " 🟨") + .replace("{63}", "🟥 ") + .replace("{63}", " 🟥"); + + if (process.env.MASTODON_ACCESS_TOKEN) { + await fetch(`https://mastodon.social/api/v1/statuses`, { + method: "POST", + headers: { + Authorization: `Bearer ${process.env.MASTODON_ACCESS_TOKEN}`, + "Idempotency-Key": `${Date.now()}`, + }, + body: `status=${encodeURIComponent(status + `\n#workoutoftheday`)}`, + }); + } +}; + main();