1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=5";
export default async function(req: Request): Promise<Response> {
// get the bracketId, gender, and year query parameters
const searchParams = new URL(req.url).searchParams;
const bracketId = searchParams.get("bracketId");
const gender = searchParams.get("gender") == "mens" ? "mens" : "womens";
const year = searchParams.get("year");
if (!bracketId || !gender || !year) {
return new Response("Missing query parameters", { status: 400 });
}
const groups = await espntcGetUsersGroups(bracketId, gender, year);
return new Response(JSON.stringify(groups), {
headers: { "Content-Type": "application/json", "cache-control": "public, max-age=3600" },
});
}
const espntcGetUsersGroups = async (bracketId: string, gender: "mens" | "womens", year: string) => {
const url = `https://fantasy.espn.com/tournament-challenge-bracket${
gender == "womens" ? "-women" : ""
}/${year}/en/game?entryID=${bracketId}`;
const text = await fetchText(url);
const selectorDivs = text
.split("group?groupID=")
.slice(1)
.map((d) => +d.split("\"")[0]);
return [...new Set(selectorDivs)];
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.