1import { get_bilibili } from "https://esm.town/v/rebelpotato/bilibili_methods";
2
3function randint(x) {
4 return Math.floor(Math.random() * x);
5}
7const video_url = "https://api.bilibili.com/x/web-interface/dynamic/region?ps=6&rid=1";
8
9export async function get_random_video(cookie) {
10 let videos = (await get_bilibili(video_url, cookie)).archives;
11 let video = videos[randint(videos.length)];
1function getBilibiliHeaders(cookie) {
2 return new Headers({
3 "connection": "keep-alive",
9}
10
11function postBilibiliHeaders(cookie) {
12 return new Headers({
13 "connection": "keep-alive",
22}
23
24export function get_bilibili(url, cookie) {
25 return fetch(url, {
26 method: "GET",
39}
40
41function post_encode(params) {
42 return Object.keys(params).map(key => encodeURIComponent(key) + "=" + encodeURIComponent(params[key])).join("&");
43}
44
45export function post_bilibili(url, post_data, cookie) {
46 return fetch(url, {
47 method: "POST",
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
1## Create an API from a [lowdb blob](https://www.val.town/v/pomdtr/lowdb)
2
3This val exports a function that takes a lowdb instance and returns a [Hono](https://hono.dev) router that can be used to interact with the data. This is the beginning of an implementation of something like [json-server](https://github.com/typicode/json-server) for Val Town.
4
5The resulting server also comes with a frontend at `/`. The code for the frontend can be found [here](https://www.val.town/v/nbbaier/dbToAPIFrontend).
32console.log(text);
33
34export async function weatherGPT() {
35 await email({ subject: "Weather Today", text });
36}
8// Fetches a random joke.
9// Fetches a random joke.
10async function fetchRandomJoke() {
11 const response = await fetch(
12 "https://official-joke-api.appspot.com/random_joke",
1049console.log("solution *2:", secondStar(input));
1050
1051function debug<T>(value: T, msg = "debug"): T {
1052 console.log(msg, value);
1053 return value;
32console.log(text);
33
34export async function weatherGPT() {
35 await email({ subject: "Weather Today", text });
36}
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
1This is a great template if you want to solve the <https://adventofcode.com> puzzles in a TDD style:
21. dump your puzzle input into the `input` function
32. copy/paste sample input and output from the page
43. once all assertions pass, the solution is calculated
5
6There is one function for each star that can be achieved.
7
8Some helpers for common tasks are defined at the end of code: `debug`, `toInt`, `exctractNumbers`, `sum`, ... ?
A helper function to build a file's email
Simple functional CSS library for Val Town
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.