Skip to content

Commit

Permalink
💄 Format moon in clearsky night hourly
Browse files Browse the repository at this point in the history
  • Loading branch information
boredland committed May 14, 2024
1 parent d0835e6 commit 9cd5042
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docs/functions/weather/[location].ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ export const onRequest: PagesFunction<Env> = async (context) => {
"temperature_2m,wind_speed_10m,weather_code,apparent_temperature,relative_humidity_2m,is_day",
daily:
"weather_code,apparent_temperature_min,apparent_temperature_max,uv_index_clear_sky_max",
hourly: "apparent_temperature,weather_code,precipitation_probability",
hourly:
"apparent_temperature,weather_code,precipitation_probability,is_day",
forecast_days: "3",
forecast_hours: "72",
...input.data,
Expand Down Expand Up @@ -186,12 +187,14 @@ export const onRequest: PagesFunction<Env> = async (context) => {
apparent_temperature: string;
weather_code: string;
precipitation_probability: string;
is_day: string;
};
hourly: {
time: string[];
apparent_temperature: number[];
weather_code: number[];
precipitation_probability: number[];
is_day: (0 | 1)[];
};
}>();

Expand All @@ -213,13 +216,15 @@ export const onRequest: PagesFunction<Env> = async (context) => {
const hour = new Date(time).getHours();
const precipitation_probability =
result.hourly.precipitation_probability[index];
const is_day = result.hourly.is_day[index];

return {
time,
temperature,
weatherCode,
hour,
precipitation_probability,
is_day,
};
})
.filter((hourly) => hourly.hour % 2 === 0);
Expand Down Expand Up @@ -249,7 +254,9 @@ export const onRequest: PagesFunction<Env> = async (context) => {
return `${hourly.hour}: ${hourly.temperature}${
result.hourly_units.apparent_temperature
} ${wmoCodeToText[language][hourly.weatherCode]} ${
wmoCodeToEmojiMap[hourly.weatherCode]
hourly.is_day === 0 && hourly.weatherCode === 0
? "🌙"
: wmoCodeToEmojiMap[hourly.weatherCode]
}${
hourly.precipitation_probability > 0
? ` ☔${hourly.precipitation_probability}%`
Expand Down

0 comments on commit 9cd5042

Please sign in to comment.