Runs every 12 hrs
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { animalWidgetJson } from "https://esm.town/v/crsven/animalWidgetJson";
import { fetchABird } from "https://esm.town/v/crsven/fetchABird";
import { getBirdPhotoUrl } from "https://esm.town/v/crsven/getBirdPhotoUrl";
import { getNextColorCombo } from "https://esm.town/v/crsven/getNextColorCombo";
import { set } from "https://esm.town/v/std/set?v=11";
export let refreshAnimalWidget = async () => {
const bird = await fetchABird();
const photoUrl = await getBirdPhotoUrl(
`${bird.gen} ${bird.sp}`,
);
const message = `${bird.en} (${bird.cnt})`;
const colorCombo = await getNextColorCombo();
const newState = { ...animalWidgetJson };
const birdName = bird.en.replace(" ", "+");
newState.data.content_url =
`https://api.val.town/express/@crsven.embedBirdSound?args=${birdName},${bird.file},${photoUrl}`;
newState.layouts.hello_small.styles.colors.background.color = colorCombo.background;
newState.layouts.hello_small.styles.colors.text.color = colorCombo.text;
newState.layouts.hello_small.layers[2].rows[0].cells[0].text.string = message;
newState.layouts.hello_small.layers[0].rows[0].cells[0].image.url = photoUrl;
await set("animalWidgetJson", newState);
};