
@cjpais
1 like3 public vals
Joined May 19, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const weather = async (city: string) => {
marcel
.weather(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
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
let simpleWeather = async (city: string) =>
marcel
.weather(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