1import { fetch } from "https://esm.town/v/std/fetch";
2
3export const extractWikipediaMainText = async () => {
7 const extractWikipediaContent = async (url) => {
8 try {
9 const response = await fetch(url);
10 const html = await response.text();
11 const parser = new DOMParser();
20 return `${textContent.trim()}`;
21 } catch (error) {
22 console.log("Error fetching Wikipedia content:", error);
23 return `An error occurred while fetching the Wikipedia content. ${error}`;
24 }
25 };
27 const randomWikiURL = "https://en.wikipedia.org/wiki/Special:Random";
28 try {
29 const response = await fetch(randomWikiURL, { redirect: "manual" });
30 const location = response.headers.get("location");
31 return location;
32 } catch (error) {
33 console.log("Error fetching random Wikipedia URL:", error);
34 return `An error occurred while fetching the random Wikipedia URL. ${error}`;
35 }
36 };
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export const getRandomArticleInCategory = async (category) => {
13 const listUrl =
14 `https://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:${encodedCategory}&cmlimit=500&format=json&origin=*`;
15 const listResponse = await fetch(listUrl);
16 const listData = await listResponse.json();
17 if (!listData.query.categorymembers.length) {
28 encodeURIComponent(randomArticle)
29 }&format=json&utf8=1&origin=*`;
30 const contentResponse = await fetch(contentUrl);
31 const contentData = await contentResponse.json();
32 const pageId = Object.keys(contentData.query.pages)[0];
38 }
39 catch (error) {
40 console.log("Error fetching Wikipedia content:", error);
41 return `An error occurred while fetching the Wikipedia content. ${error}`;
42 }
43};
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 { fetch } from "https://esm.town/v/std/fetch";
2
3export let goodReads = (url) => {
4 const resp = await fetch(url);
5
6 console.log("url: ", url, resp);
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3// GitHub gists
4export let githubGists = fetchJSON(
5 "https://api.github.com/users/stevekrouse/gists"
6);
5 // a search term might've been passed in
6 // const url = https://something@domain.com?searchterm=${req.query.arg}
7 // let response = await fetch(url);
8 // const theText = JSON.parse(await response.text());
9 // continue assuming theText had been filled with response text
1import { discordFetch } from "https://esm.town/v/vtdocs/discordFetch";
2
3export const discordGetMembers = async (
9 let highestId = BigInt(0);
10 while (true) {
11 const result = await discordFetch(
12 botToken,
13 `/guilds/${serverId}/members?limit=1000&after=${highestId}`,
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export const untitled_xqPioNn3 = await fetch("https://www.baidu.com");
1import process from "node:process";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
3
4export let getMe = fetchJSON(`https://api.val.town/v1/me`, {
5 headers: {
6 Authorization: `Bearer ${process.env.valtownToken}`,
1import process from "node:process";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
3
4export async function stockPriceViz(req: Request) {
7 const symbol = params.get("symbol");
8 const d = params.get("d");
9 const resData = await fetchJSON(
10 `https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=${symbol}&interval=${d}min&apikey=${process.env.alphaVantage}`,
11 );