15 (c) => c.text("current state is" + currentState),
16 );
17 return app.fetch(req);
18};
1import { fetch } from "https://esm.town/v/std/fetch";
2import { normalizeURL } from "https://esm.town/v/stevekrouse/normalizeURL?v=3";
3
4export const fetchJSON = async (url: string, options?: any) => {
5 let f = await fetch(normalizeURL(url), {
6 redirect: "follow",
7 ...options,
16 }
17 catch (e) {
18 throw new Error(`fetchJSON error: ${e.message} in ${url}\n\n"${t}"`);
19 }
20};
21// Forked from @stevekrouse.fetchJSON
1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
2
3export let badArgs1 = (async () => {
4 // this should error helpfully
5 console.log(
6 await fetchText(
7 "https://api.val.town/v1/run/stevekrouse.id",
8 {
14 // this should error helpfully
15 console.log(
16 await fetchText(
17 "https://api.val.town/v1/run/stevekrouse.id",
18 {
26 // this is a proper call
27 console.log(
28 await fetchText(
29 "https://api.val.town/v1/run/stevekrouse.id",
30 {
1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=5";
2
3// Random math fact
4export let mathFact = fetchText(
5 "http://numbersapi.com/random/math"
6);
1import { filterAlertsByLineAndStation } from "https://esm.town/v/roop/filterAlertsByLineAndStation";
2import { fetchAlerts } from "https://esm.town/v/roop/fetchAlerts";
3
4export async function currentCommuteAlertMessages() {
5 const alerts = (await fetchAlerts()).entity;
6 const filtered = filterAlertsByLineAndStation(alerts);
7 const messages = filtered.map((a) => ({
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3export let redditMatches = async ({ username, filters, current_state, options }) => {
23 let params = last ? `?before=${last}` : "";
24 let subreddit_matches = [];
25 let data = await fetchJSON(
26 `https://www.reddit.com/r/${subreddit}/new/.json${params}`
27 );
73
74 last = data.data.children[0].data.name;
75 data = await fetchJSON(
76 `https://www.reddit.com/r/${subreddit}/new/.json?before=${last}`
77 );
1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=5";
2
3export const tacUrlToBibtex = async (url: string) => {
4 const cheerio = await import("npm:cheerio");
5 const html = await fetchText(url);
6 const $ = cheerio.load(html);
7 const title = $("h1").text().trim().replace(/\s+/g, " ");
1// This tries to fetch a specific post on multiple Lemmpy instances
2// and can try to fix missing comments on a specific instance.
3export async function getLemmyPosts(instance: string, communityName: string) {
4 const { LemmyHttp } = await import("npm:lemmy-js-client");
5 let client = new LemmyHttp(`https://${instance}`, {
6 fetchFunction: fetch,
7 });
8 const { posts } = await client.getPosts({
121 "https://api.val.town/v1/run/rodrigotello.updateDinoScoreboard";
122
123 fetch(apiUrl, {
124 method: "POST",
125 headers: {
139 .then((result) => {
140 console.log("Scoreboard updated:", result);
141 // Update the scoreboard variable with the fetched data
142 scoreboard = result;
143 })
157 text("Press SPACE to play again", width / 2, height / 2 + 10);
158
159 // Fetch the latest scoreboard data
160 const apiUrl =
161 "https://api.val.town/v1/run/rodrigotello.dinoGameScoreboard";
1import { fetchHtmlDom } from "https://esm.town/v/aeaton/fetchHtmlDom";
2
3export async function peelSessionLetters() {
4 const url = `https://www.bbc.co.uk/radio1/johnpeel/artists/`;
5 const dom = await fetchHtmlDom(url);
6 const items = dom.querySelectorAll(
7 "#alphabetical-sub-section-navigation > ul > li > a",