1// This approach directly uses axios to request the Pinboard API.
2// It requires a Pinboard API token, which is set as a secret in Val Town.
3
4import axios from "npm:axios";
8
9 if (!token) {
10 return Response.json({ error: "Pinboard API token not set" }, { status: 500 });
11 }
12
13 try {
14 const response = await axios.get(
15 `https://api.pinboard.in/v1/posts/recent?auth_token=${token}&format=json&count=10`,
16 );
17
18 if (response.status !== 200) {
19 throw new Error(`Pinboard API returned status ${response.status}`);
20 }
21
22 if (!response.data || !Array.isArray(response.data.posts)) {
23 throw new Error("Unexpected response format from Pinboard API");
24 }
25
45 }
46 } else if (error.request) {
47 errorMessage += ": No response received from Pinboard API";
48 } else {
49 errorMessage += `: ${error.message}`;
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
4
5export default async function main(req: Request): Promise<Response> {
11 const threeMonthsAgo = new Date(Date.now() - 90 * 24 * 60 * 60 * 1000).toISOString();
12 const response = await fetch(
13 `https://api.github.com/users/${username}/events?per_page=100&since=${threeMonthsAgo}`,
14 );
15 const data = await response.json();
16 if (!Array.isArray(data)) {
17 throw new Error(`Unexpected GitHub API response for user ${username}`);
18 }
19 return data;
57 const user2Summary = summarizeActivity(user2Data);
58
59 const openai = new OpenAI(OPENAI_API_KEY);
60 const completion = await openai.chat.completions.create({
61 model: "gpt-3.5-turbo",
26## Response
27
28The API returns a plain text response with AI-generated collaboration suggestions, including:
29
301. Potential collaborative projects
1// This approach fetches GitHub activity for two users specified in the URL,
2// sends it to OpenAI for analysis, and returns collaboration suggestions.
3// It uses the GitHub API (which doesn't require authentication for public data)
4// and the OpenAI API (which does require an API key).
5// Tradeoff: We're using an inline API key for simplicity, which isn't ideal for security.
6// Note: This might hit rate limits for the GitHub API due to fetching a year of data.
7
8import { OpenAI } from "https://esm.town/v/std/openai";
9
10const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
11
12export default async function main(req: Request): Promise<Response> {
17 async function fetchUserActivity(username: string) {
18 const oneYearAgo = new Date(Date.now() - 365 * 24 * 60 * 60 * 1000).toISOString();
19 const response = await fetch(`https://api.github.com/users/${username}/events?per_page=100&since=${oneYearAgo}`);
20 const data = await response.json();
21 if (!Array.isArray(data)) {
22 throw new Error(`Unexpected GitHub API response for user ${username}`);
23 }
24 return data;
54 const user2Summary = summarizeActivity(user2Data);
55
56 const openai = new OpenAI(OPENAI_API_KEY);
57 const completion = await openai.chat.completions.create({
58 model: "gpt-3.5-turbo",
1// This val receives text input, sends it to OpenAI to generate relationships,
2// and returns a newline-delimited list of relationships.
3// It uses the OpenAI API to generate the relationships.
4// Tradeoff: This approach relies on an external API, which may have rate limits or costs.
5
6// Usage with curl:
1// This approach uses the GitHub API without authentication, which is subject to rate limiting.
2// We'll fetch and process the GitHub activity data, and render it as a nicely designed website
3// using Vue for templating and Tailwind for styling.
9
10async function fetchGitHubEvents(username: string) {
11 const response = await fetch(`https://api.github.com/users/${username}/events/public`, {
12 headers: {
13 "User-Agent": "Val-Town-Script",
15 });
16 if (!response.ok) {
17 throw new Error(`GitHub API request failed: ${response.status}`);
18 }
19 return await response.json();
1export const starterTheme = {
2 fontLink: `<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap" rel="stylesheet">`,
3 styles: `
4 /* General styles */
66 <title>Lista de alimentação</title>
67 <link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
68 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
69 <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap" rel="stylesheet">
70 <script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
71 <style>
160 <title>Já Comeu?</title>
161 <link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
162 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
163 <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap" rel="stylesheet">
164 <script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
165 <style>
1import { API_URL } from "https://esm.town/v/std/API_URL";
2import { LibsqlError, type TransactionMode } from "npm:@libsql/client";
3import { z } from "npm:zod";
35
36async function execute(statement: InStatement): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
39 headers: {
49
50async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
51 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
52 method: "POST",
53 headers: {
3// 4.1%
4const maximumMortageRate = 4.1;
5const fredApiKey = Deno.env.get("FRED_API_SECRET_KEY");
6const fredApiUrl =
7 `https://api.stlouisfed.org/fred/series/observations?series_id=MORTGAGE30US&api_key=${fredApiKey}&file_type=json&sort_order=desc&limit=1`;
8
9export default async function main(req: Request) {
10 try {
11 const response = await fetch(fredApiUrl);
12 const data = await response.json();
13