Skip to content

Commit

Permalink
ez
Browse files Browse the repository at this point in the history
  • Loading branch information
John Ottenlips authored and John Ottenlips committed Sep 20, 2023
2 parents 21aca7c + 2954155 commit 8df6a73
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/wodaboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
VB_SUB_SECRET: ${{ secrets.VB_SUB_SECRET }}
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 [[email protected]](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
```
```

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)
Binary file modified bun.lockb
Binary file not shown.
47 changes: 40 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) => {
Expand All @@ -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();

0 comments on commit 8df6a73

Please sign in to comment.