Skip to content

Commit a27e8eb

Browse files
authored
Merge pull request #32 from infinitel8p/hotfix
2 parents db76817 + f2bf777 commit a27e8eb

3 files changed

Lines changed: 31 additions & 13 deletions

File tree

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
OPENWEATHERMAP_API_KEY=
2-
OPENWEATHERMAPONECALL_API_KEY=
1+
OPENWEATHERMAP_API_KEY=# Replace with your OpenWeatherMap API key
2+
OPENWEATHERMAPONECALL_API_KEY=# Replace with your OpenWeatherMap One Call API key

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/index.astro

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,28 @@ const currentDate = time.toLocaleDateString("de-DE", {
4646
hour12: false,
4747
});
4848
49+
// res = await fetch(
50+
// `https://api.openweathermap.org/data/2.5/forecast/daily?lat=${lat}&lon=${lon}&cnt=8&lang=DE&units=metric&appid=${env.OPENWEATHERMAP_API_KEY}`
51+
// );
4952
res = await fetch(
50-
`https://api.openweathermap.org/data/2.5/forecast/daily?lat=${lat}&lon=${lon}&cnt=8&lang=DE&units=metric&appid=${env.OPENWEATHERMAP_API_KEY}`
53+
`https://api.openweathermap.org/data/3.0/onecall?lat=${lat}&lon=${lon}&cnt=8&lang=DE&units=metric&exclude=current,minutely,hourly,alerts&appid=${env.OPENWEATHERMAPONECALL_API_KEY}`
5154
);
5255
const weeklyWeather = await res.json();
56+
console.log(weeklyWeather);
5357
58+
// res = await fetch(
59+
// `https://api.openweathermap.org/data/2.5/forecast/hourly?lat=${lat}&lon=${lon}&cnt=24&lang=DE&units=metric&appid=${env.OPENWEATHERMAP_API_KEY}`
60+
// );
5461
res = await fetch(
55-
`https://api.openweathermap.org/data/2.5/forecast/hourly?lat=${lat}&lon=${lon}&cnt=24&lang=DE&units=metric&appid=${env.OPENWEATHERMAP_API_KEY}`
62+
`https://api.openweathermap.org/data/3.0/onecall?lat=${lat}&lon=${lon}&cnt=8&lang=DE&units=metric&exclude=current,minutely,daily,alerts&appid=${env.OPENWEATHERMAPONECALL_API_KEY}`
5663
);
5764
const hourlyWeather = await res.json();
5865
59-
const hourlyChartLabels = hourlyWeather.list.map((h) =>
66+
const hourlyChartLabels = hourlyWeather.hourly.map((h) =>
6067
formatToBerlinTime(h.dt)
6168
);
62-
const hourlyTemperatures = hourlyWeather.list.map((h) =>
63-
Math.round(h.main.temp)
64-
);
65-
const hourlyPrecipitation = hourlyWeather.list.map((h) => {
69+
const hourlyTemperatures = hourlyWeather.hourly.map((h) => Math.round(h.temp));
70+
const hourlyPrecipitation = hourlyWeather.hourly.map((h) => {
6671
if (h.rain) {
6772
return h.rain["1h"];
6873
} else {
@@ -82,7 +87,6 @@ try {
8287
oneCall = JSON.parse(data);
8388
}
8489
85-
8690
const hourlyUVIndex = oneCall.hourly.slice(1, 25).map((h) => {
8791
if (h.uvi) {
8892
return Math.round(h.uvi);
@@ -240,7 +244,7 @@ const darkColors = [
240244
<span class="text-4xl font-bold">
241245
{
242246
Math.round(
243-
weeklyWeather.list[0].temp.min
247+
weeklyWeather.daily[0].temp.min
244248
)
245249
}<span class="text-2xl">°C</span>
246250
</span>
@@ -254,7 +258,7 @@ const darkColors = [
254258
<span class="text-4xl font-bold">
255259
{
256260
Math.round(
257-
weeklyWeather.list[0].temp.max
261+
weeklyWeather.daily[0].temp.max
258262
)
259263
}<span class="text-2xl">°C</span>
260264
</span>
@@ -418,7 +422,7 @@ const darkColors = [
418422
},
419423
]}>
420424
{
421-
weeklyWeather.list
425+
weeklyWeather.daily
422426
.slice(1)
423427
.map((item) => (
424428
<SingleWeatherCard

0 commit comments

Comments
 (0)