1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3export async function raw(val: `@${string}.${string}`) {
4 const [owner, name] = val.slice(1).split(".") as string[];
5 return fetchJSON(
6 `https://api.val.town/v1/alias/${owner}/${name}`,
7 )
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export async function run(
10 const method = data ? "POST" : "GET";
11 const body = data ? JSON.stringify({ args: data }) : undefined;
12 const response = await fetch(url, { method, headers, body });
13 return await response.json();
14}
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3// Github profile
4export let githubUser = fetchJSON(
5 "https://api.github.com/users/stevekrouse"
6);
1import { fetch } from "https://esm.town/v/std/fetch";
2import process from "node:process";
3
18 console.log("code: ", code);
19 try {
20 const gh_res = await fetch(
21 `https://github.com/login/oauth/access_token?code=${code}&client_id=${process.env.sanguineGithubClientId}&client_secret=${process.env.sanguineGithubClientSecret}`,
22 {
31 },
32 );
33 console.log("made it past fetch");
34 console.log("gh_res: ", gh_res);
35 if (!gh_res.ok) {
36 throw new Error(`Failed to fetch`);
37 }
38 const gh_res_json = await gh_res.json();
42 const accessToken = data?.access_token;
43 console.log("access_token: ", data);
44 // // Fetch user information using the access token
45 const userResponse: any = await fetch("https://api.github.com/user", {
46 headers: {
47 "Authorization": `Bearer ${accessToken}`,
55 }
56 catch (err) {
57 console.error("Error fetching access token or user data:", err);
58 res.status(500).send("Authentication failed");
59 }
1import { fetch } from "https://esm.town/v/std/fetch";
2
3// https://www.schools.nyc.gov/docs/default-source/school-menus/2023-2024/september/pre-k---8-express-hot-lunch-menu
4//
5export let fetchDOEMenu: (opts: {schoolYear: `${number}-${number}`, month: string, menuType: string}) = (async ({schoolYear, month, menuType}) => {
6 const resp = await fetch(
7 `https://www.schools.nyc.gov/docs/default-source/school-menus/${schoolYear}/${month}/${menuType}`,
8 {
8 isInterval?: boolean;
9 }) =>
10 `fetch('https://api.val.town/eval/@vez.editVal(${JSON.stringify(body)})')`;
11 return res.send(`<h1>Shitty Val Town 2</h1>
12${(await getAllVals("@vez")).map(({ code, name }) => {
13 const editorId = `${name}-editor`;
14 const onClick = `(document.getElementById('${name}-button').textContent = 'save 🔄'), fetch('https://api.val.town/eval/@vez.editVal', { method: 'POST', body: JSON.stringify({ name: '${name}', code: document.getElementById('${editorId}').value })}).then(()=>(document.getElementById('${name}-button').textContent = 'save ✅'))`;
15 return `<h2>${name}</h2>
16<textarea id="${editorId}" rows="20" cols="120">${escapeHtml(
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3export async function postTweet({ accessToken, text, reply }: {
8 };
9}) {
10 return fetchJSON(`https://api.twitter.com/2/tweets`, {
11 method: "POST",
12 headers: {
36submitButton.addEventListener("click", async () => {
37 const webhookUrl = webhookUrlInput.value;
38 const response = await fetch(webhookUrl, {
39 method: "POST",
40 });
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export let requestGoogleNgram = async (
8 smoothing = 5,
9) => {
10 let response = await fetch(
11 `https://books.google.com/ngrams/json?content=${query}&year_start=${year_start}&year_end=${year_end}&corpus=${corpus}&smoothing=${smoothing}`,
12 ).then((p) => p.json());
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export async function wttrGetForecast({
7 const wttrLocation = encodeURIComponent(location);
8 const wttrLang = encodeURIComponent(languageCode);
9 const res = await fetch(
10 `https://wttr.in/${wttrLocation}?lang=${wttrLang}&format=j1`
11 );