Avatar

@cjpais

1 like5 public vals
Joined May 19, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { weather as weather2 } from "https://esm.town/v/marcel/weather?v=4";
export const weather = async (city: string) => {
weather2(city)
.then(({ weather }) => ({
w: weather,
}))
.then(({ w }) =>
w.map((d) => ({
maxTempF: `${d.maxtempF}`,
minTempF: `${d.mintempF}`,
description: d.hourly.map((h) => h.weatherDesc[0].value),
}))
);
};
// Forked from @marcel.weather
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { fetch } from "https://esm.town/v/std/fetch";
export const simpleClimbing = (async () => {
const areas = [
{
name: "Holcomb",
id: 679,
mtnProjId: 105805238,
},
{
name: "Red Rock",
id: 560,
mtnProjId: 105731932,
},
{
name: "Joshua Tree",
id: 506,
mtnProjId: 105720495,
},
{
name: "Tahquitz",
id: 517,
mtnProjId: 105788020,
},
{
name: "Yosemite",
id: 518,
mtnProjId: 105833381,
},
{
name: "Woodson",
id: 718,
mtnProjId: 105791148,
},
{
name: "Culp",
id: 947,
mtnProjId: 106116317,
},
{
name: "Eagle Peak",
id: 1054,
mtnProjId: 107008184,
},
{
name: "El Cajon",
id: 750,
mtnProjId: 105793290,
},
{
name: "New Jack",
id: 677,
mtnProjId: 105865045,
},
{
name: "Mission Gorge",
id: 738,
mtnProjId: 105790250,
},
];
// const rawWeatherData = await fetch(
// `https://api.climbingweather.com/area/detail/738?days=1`,
// ).then((r) => r.json());
const rawWeatherData = await Promise.all(
areas.map(async (
a,
) => (await fetch(
`https://api.climbingweather.com/area/detail/${a.id}?days=1`,
).then((r) => r.json()).then((d) => ({
...d,
...a,
})))),
);
return rawWeatherData.map((w) => ({
id: w.areaId,
name: w.name,
hi: w.forecast.daily.data[0].temperatureHigh,
lo: w.forecast.daily.data[0].temperatureLow,
precipProb: parseFloat(w.forecast.daily.data[0].precipProbability),
windSpeed: w.forecast.daily.data[0].windSpeed,
windGust: w.forecast.daily.data[0].windGust,
mtnProjURL: `https://www.mountainproject.com/area/${w.mtnProjId}`,
color: w.color,
// hi: w.forecast.daily.data[0].temperatureHigh,
// lo: w.forecast.daily.data[0].temperatureLow,
}));
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { fetch } from "https://esm.town/v/std/fetch";
export const simpleSurf = (async () => {
// fetch these from the surfline page
const spotIds = [
"5842041f4e65fad6a770883f",
"5842041f4e65fad6a77088b4",
"5842041f4e65fad6a77088af",
"5842041f4e65fad6a770888b",
"5842041f4e65fad6a7708b32",
];
const spots = spotIds.join(",");
const surfForecast = await fetch(
`https://services.surfline.com/kbyg/spots/batch?units%5BswellHeight%5D=FT&units%5Btemperature%5D=F&units%5BtideHeight%5D=FT&units%5BwaveHeight%5D=FT&units%5BwindSpeed%5D=KTS&spotIds=${spots}`,
).then((r) => r.json()).then((d) => d.data);
return surfForecast.map((f) => ({
id: f._id,
name: f.name,
surflineURL: `https://www.surfline.com/surf-report/${
f.name.toLowerCase().replace(/[\s']/g, "-")
}/${f._id}`,
waterTemp: `${f.waterTemp.min}°`,
windSpeed: `${Math.round(f.wind.speed * 1.15078)}`,
windDirection: f.wind.directionType.replace("Cross-shore", "cross"),
waveHeight: `${f.waveHeight.min}-${f.waveHeight.max}`,
rating: f.rating.key,
tide: {
prevTideHeight: f.tide.previous.height,
prevTideTime: f.tide.previous.timestamp * 1000,
currTideHeight: f.tide.current.height,
currTideTime: f.tide.current.timestamp * 1000,
nextTideHeight: f.tide.next.height,
nextTideTime: f.tide.next.timestamp * 1000,
},
stream: f.cameras[0] ? f.cameras[0].streamUrl : "none",
}));
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { fetch } from "https://esm.town/v/std/fetch";
export const glifJson = async (id: string) => {
const getRandom = (list) => {
const shuffledList = list.sort(function () {
return 0.5 - Math.random();
});
const numToPick = Math.min(20, shuffledList.length);
var randomItems = [];
for (let i = 0; i < numToPick; i++)
randomItems.push(shuffledList[i]);
return randomItems;
};
const url = `https://alpha.glif.xyz/api/glifs?id=${id}`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data) {
const filteredInputs = data[0].spellRuns.filter((r) => r.inputs).map(
(r) => r.inputs
);
const randomInputs = getRandom(filteredInputs);
return { data: randomInputs };
}
else {
throw new Error("Invalid data structure");
}
}
catch (error) {
return { error: error.message };
}
};
// Forked from @jamiedubs.glifJson
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { weather as weather2 } from "https://esm.town/v/marcel/weather?v=4";
export let simpleWeather = async (city: string) =>
weather2(city)
.then(({ current_condition, weather }) => ({
c: current_condition[0],
w: weather,
}))
.then(({ c, w }) => ({
temp: `${c.temp_F}`,
feelsLike: `${c.FeelsLikeF}`,
description: c.weatherDesc?.[0]?.value,
windSpeed: `${c.windspeedMiles}mph`,
forecast: w.map((f) => ({
date: new Date(f.date),
minTemp: `${f.mintempF}`,
maxTemp: `${f.maxtempF}`,
hourly: f.hourly.map((h) => ({
description: h.weatherDesc?.[0]?.value,
windSpeed: `${h.windspeedMiles}mph`,
})),
})),
}));
// Forked from @patrickjm.simpleWeather
Next