Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { fetchPelotonData } from "https://esm.town/v/andreterron/fetchPelotonData";
import { blob } from "https://esm.town/v/std/blob?v=3";
import { rpc } from "https://esm.town/v/std/rpc";
export let myPelotonWorkouts = async () => {
let pelotonCache: any;
try {
pelotonCache = await blob.getJSON("pelotonCache");
} catch (e) {
console.error(e);
}
if (!pelotonCache || Date.now() > pelotonCache.time + 8 * 60 * 1000) {
const value = await fetchPelotonData();
pelotonCache = {
value,
time: Date.now(),
};
await blob.setJSON("pelotonCache", pelotonCache);
}
return pelotonCache.value;
};
andreterron-mypelotonworkouts.web.val.run
March 24, 2024