3## Fetch Paginated Data
4
5This val exports a function that loops through paginated API responses and returns the combined data as an array. It expects pagination with `next` and there to be a `data` property in the API response. This conforms to the Val Town API, so this function is useful when fetching paginated Val Town API responses for creating custom folders in [pomdtr's vscode extension](https://github.com/pomdtr/valtown-vscode).
6
7Usage:
9```ts
10const id = <vt user id>
11await fetchPaginatedData(`https://api.val.town/v1/users/${id}/vals`, {
12 headers: { Authorization: `Bearer ${Deno.env.get("valtown")}` },
13});
32
33 const response: telegramResponse = await fetchJSON(
34 `https://api.telegram.org/bot${botToken}/sendMessage`,
35 {
36 method: "POST",
1import { Resend } from "resend";
2
3const resend = new Resend(Deno.env.get("RESEND_API_KEY"));
4
5// resend.emails.send({
131const fetchForecast = async () => {
132 const response = await fetch(
133 `https://api.openweathermap.org/data/2.5/forecast?lat=${latitude}&lon=${longitude}&units=metric&appid=${openWeatherMapAppId}`,
134 );
135 const data = await response.json();
155const sendTextWithTelegram = async (text: string) => {
156 const telegramSendUrl =
157 `https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage?chat_id=${TELEGRAM_CHAT_ID}&parse_mode=HTML&disable_notification=true&text=${text}`;
158 await fetch(telegramSendUrl);
159};
1const API_KEY = Deno.env.get("WUNDERGROUND_API_KEY");
2const OPENWEATHERMAP_API_KEY = Deno.env.get("OPENWEATHERMAP_APP_ID");
3const LATITUDE = Deno.env.get("LATITUDE");
4const LONGITUDE = Deno.env.get("LONGITUDE");
7const WUNDERGROUND_STATION_ID = Deno.env.get("WUNDERGROUND_STATION_ID");
8
9const fetchLatestDataFromWunderground = async (stationId = WUNDERGROUND_STATION_ID, apiKey = API_KEY) => {
10 const baseUrl = "https://api.weather.com/v2/pws/observations/current?";
11 const url = `${baseUrl}stationId=${stationId}&format=json&units=m&numericPrecision=decimal&apiKey=${apiKey}`;
12 try {
13 const response = await fetch(url);
51const fetchDataFromOpenWeatherMap = async () => {
52 const response = await fetch(
53 `https://api.openweathermap.org/data/2.5/weather?lat=${LATITUDE}&lon=${LONGITUDE}&units=metric&appid=${OPENWEATHERMAP_API_KEY}`,
54 );
55 const weatherForecastData = await response.json();
70const sendTextWithTelegram = async (text: string) => {
71 const telegramSendUrl =
72 `https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage?chat_id=${CHAT_ID}&parse_mode=HTML&text=${text}`;
73 await fetch(telegramSendUrl);
74};
6
71. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1149 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1150 <title>CerebrasCoder</title>
1151 <link rel="preconnect" href="https://fonts.googleapis.com" />
1152 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153 <link
1154 href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1155 rel="stylesheet"
1156 />
1165 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169
6
71. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
212 } catch (error) {
213 Toastify({
214 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215 position: "center",
216 duration: 3000,
1024 };
1025 } else {
1026 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027 const completion = await client.chat.completions.create({
1028 messages: [
1149 <meta name="viewport" content="width=device-width, initial-scale=1.0">
1150 <title>CerebrasCoder</title>
1151 <link rel="preconnect" href="https://fonts.googleapis.com" />
1152 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153 <link
1154 href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1155 rel="stylesheet"
1156 />
1165 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169
1Deno.env.get(VAL_TOWN_API_KEY);
2
3console.log(VAL_TOWN_API_KEY);