23
24 capturePostHogEvent(
25 Deno.env.get("phProjectAPIKey"),
26 webhookPayload.sender.login,
27 "GitHub Star",
23
24 capturePostHogEvent(
25 Deno.env.get("phProjectAPIKey"),
26 webhookPayload.sender.login,
27 "GitHub Star",
24}
25async function getUploadURL(): Promise<string> {
26 const data = await (await fetch("https://www.val.town/api/trpc/generateImageUploadUrl", {
27 "headers": {
28 "content-type": "application/json",
15 }),
16 );
17 const dataReq = await fetch(`https://api.pinata.cloud/pinning/pinFileToIPFS`, {
18 method: "POST",
19 headers: {
28
29 const req = await fetch(
30 "https://api.pinata.cloud/data/pinList?metadata[keyvalues]={\"level\":{\"value\":\"200\",\"op\":\"eq\"}}",
31 {
32 method: "GET",
196);
197app.get("/camera-ascii/:id", async (c) => {
198 const url = "https://webcams.nyctmc.org/api/cameras/" + c.req.param("id") + "/image";
199 const { stringColor } = await imageToAscii(url, 150);
200 return new Response(stringColor, { headers: { "Content-Type": "text/plain" } });
203 "/camera/:id",
204 async (c) => {
205 const url = "https://webcams.nyctmc.org/api/cameras/" + c.req.param("id") + "/image";
206 const { string, stringColor } = await imageToAscii(url, 150);
207 return new Response(
258app.get("/camera-text-stream/:id", async (c) => {
259 let timerId: number | undefined;
260 const url = "https://webcams.nyctmc.org/api/cameras/" + c.req.param("id") + "/image";
261 const body = new ReadableStream({
262 async start(controller) {
15
16// Takoma Park, MD weather forecast
17// https://weather-gov.github.io/api/gridpoints
18const NOAA_URL_TKPK = "https://api.weather.gov/gridpoints/LWX/97,75/forecast/hourly";
19
20interface Period {
52}
53
54// Sleep a random amount of seconds (to respect NOAA's API).
55async function sleepRand(seconds: number) {
56 const s = Math.random() * seconds * 1000;
3export default async function(req: Request): Promise<Response> {
4 const { string, stringColor } = await imageToAscii(
5 "https://webcams.nyctmc.org/api/cameras/9fa5b0dd-e955-449e-97e1-9c53ad9c23a8/image",
6 150,
7 );
1Migrated from folder: Archive/geolocation_api_demo
12
13
14NYC has a bunch of traffic cameras and makes them available through static images [like this one](https://webcams.nyctmc.org/api/cameras/858ef4e8-5058-4db2-96e2-70f71b65aa24/image). If you refresh the page you'll see the image update every 2 seconds or so. I thought it might be fun to make these cameras viewable as an ASCII art video feed. I made a [small library](https://www.val.town/v/maxm/imageToAscii) that takes most of its logic from [this repo](https://github.com/victorqribeiro/imgToAscii). You can see a basic example of how to convert [any image to ASCII here](https://www.val.town/v/maxm/asciiImageExample).
15
16I pull in [NYC GeoJSON from here](https://observablehq.com/@miaozhang/maps) and then hook up a Server-Sent Events endpoint to stream the ASCII updates to the browser. (Polling would work just as well, I've just been on a bit of a SSE kick lately.)
2
3// use my private proxy
4setEnv("VALTOWN_API_URL", "https://pomdtr-tursoproxy.web.val.run");
5
6// need to be dynamic