3const ALPHA_VANTAGE_API_KEY = "your_api_key_here"; // Replace with your actual API key
4
5async function fetchStockData(symbol: string) {
6 const apiUrl =
7 `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${symbol}&apikey=${ALPHA_VANTAGE_API_KEY}`;
8 const response = await fetch(apiUrl);
9 const data = await response.json();
27
28// This is the default export for Val Town
29export default async function(req: Request): Promise<Response> {
30 const url = new URL(req.url);
31 const symbol = url.searchParams.get("symbol");
6);
7
8export async function uptimeCheck(url: string) {
9 let reason: string, status: number, end: number;
10 let ok = true;
5import { renderToString } from "npm:react-dom/server";
6
7function StatusRow({ rows }) {
8 return (
9 <div className="w-full flex flex-col space-y-2">
28}
29
30function StatusSection({ url, rows }) {
31 const sectionRows = rows.filter(row => row[0] === url);
32 const percentUp = Math.round((sectionRows.filter(row => row[1]).length / sectionRows.length) * 100);
44}
45
46export default async function(req: Request): Promise<Response> {
47 const { rows } = await sqlite.execute(
48 "select url, ok, duration, timestamp from uptime order by timestamp desc limit 200",
1export default async function(req: Request): Promise<Response> {
2 return Response.json({ ok: false });
3}
4import { createRoot } from "https://esm.sh/react-dom/client";
5
6function App() {
7 const [file, setFile] = useState(null);
8 const [tableName, setTableName] = useState("");
66}
67
68function client() {
69 createRoot(document.getElementById("root")).render(<App />);
70}
72if (typeof document !== "undefined") { client(); }
73
74export default async function server(request: Request): Promise<Response> {
75 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
76 const { parse } = await import("https://esm.sh/csv-parse/sync");
79 const KEY = "csvToSqliteUploader";
80
81 function sanitizeColumnName(name: string): string {
82 return name.replace(/[^a-zA-Z0-9_]/g, "_").replace(/^(\d)/, "_$1");
83 }
42);
43
44export default async function(req: Request): Promise<Response> {
45 return Response.json(
46 await db.query(`
2// It supports generating square images with a single dimension parameter or rectangular images with two dimension parameters.
3
4export default async function server(request: Request): Promise<Response> {
5 const url = new URL(request.url);
6 const parts = url.pathname.split('/').filter(Boolean);
95 <p>Start generating your own kitten images by using the form above or modifying the URL!</p>
96 <script>
97 document.getElementById('kittenForm').addEventListener('submit', function(e) {
98 e.preventDefault();
99 const width = document.getElementById('width').value;
3import { createRoot } from "https://esm.sh/react-dom/client";
4// last stable version is v138
5function App() {
6 const [url, setUrl] = useState("");
7 const [result, setResult] = useState(null);
68}
69
70function client() {
71 console.log("Initializing client-side React application");
72 createRoot(document.getElementById("root")).render(<App />);
77}
78
79async function scrapePage(url) {
80 console.log(`Starting to scrape page: ${url}`);
81 const apiKey = Deno.env.get("ScrapingBeeAPIkey");
163}
164
165async function getApiKey() {
166 const apiKey = Deno.env.get("ScrapingBeeAPIkey");
167 if (!apiKey) {
172}
173
174async function server(request) {
175 console.log(`Received ${request.method} request for path: ${new URL(request.url).pathname}`);
176 if (request.method === "POST" && new URL(request.url).pathname === "/scrape") {
15
16 - The client-side React component makes a fetch request to "/image".
17 - This request is handled by our server function.
18
19
202. Server-side handling:
21
22 - The server function calls `blob.get("test.png")`.
23 - This `blob.get()` method makes an HTTP request to the Val Town API.
24 - The API returns a Response object containing the image data.
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=5";
3
4export async function aqi(interval: Interval) {
5 const location = "Philadelphia"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });
Simple functional CSS library for Val Town
A helper function to build a file's email
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.