|
|
|
@ -8,6 +8,10 @@ const FORMAT = {
|
|
|
|
|
type: 'number',
|
|
|
|
|
unit: 'mm',
|
|
|
|
|
},
|
|
|
|
|
precipitationProbability: {
|
|
|
|
|
type: 'number',
|
|
|
|
|
unit: '%',
|
|
|
|
|
},
|
|
|
|
|
apparentTemperature: {
|
|
|
|
|
type: 'number',
|
|
|
|
|
unit: '°C',
|
|
|
|
@ -47,39 +51,34 @@ const FORMAT = {
|
|
|
|
|
|
|
|
|
|
const getDailyData = async () => {
|
|
|
|
|
const response = await fetch(
|
|
|
|
|
'https://api.open-meteo.com/v1/forecast?latitude=43.7085&longitude=10.4036&hourly=temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,weather_code&timezone=Europe%2FBerlin&forecast_days=3',
|
|
|
|
|
'https://api.open-meteo.com/v1/forecast?latitude=43.7085&longitude=10.4036&hourly=temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,precipitation_probability,weather_code&timezone=Europe%2FBerlin&forecast_days=3',
|
|
|
|
|
)
|
|
|
|
|
const body = await response.json()
|
|
|
|
|
|
|
|
|
|
let today = {}
|
|
|
|
|
const startTime = new Date().getHours() + 1
|
|
|
|
|
for (let i = startTime; i <= 23; i++) {
|
|
|
|
|
today[i] = {
|
|
|
|
|
const dataAt = (body, i) => {
|
|
|
|
|
return {
|
|
|
|
|
temperature: body.hourly.temperature_2m[i],
|
|
|
|
|
precipitation: body.hourly.precipitation[i],
|
|
|
|
|
precipitationProbability: body.hourly.precipitation_probability[i],
|
|
|
|
|
apparentTemperature: body.hourly.apparent_temperature[i],
|
|
|
|
|
weatherCode: body.hourly.weather_code[i],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let today = {}
|
|
|
|
|
const startTime = new Date().getHours() + 1
|
|
|
|
|
for (let i = startTime; i <= 23; i++) {
|
|
|
|
|
today[i] = dataAt(body, i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let tomorrow = {}
|
|
|
|
|
for (let i = 0; i <= 23; i++) {
|
|
|
|
|
tomorrow[i] = {
|
|
|
|
|
temperature: body.hourly.temperature_2m[24 + i],
|
|
|
|
|
precipitation: body.hourly.precipitation[24 + i],
|
|
|
|
|
apparentTemperature: body.hourly.apparent_temperature[24 + i],
|
|
|
|
|
weatherCode: body.hourly.weather_code[24 + i],
|
|
|
|
|
}
|
|
|
|
|
tomorrow[i] = dataAt(body, 24 + i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let dayAfterTomorrow = {}
|
|
|
|
|
for (let i = 0; i <= 23; i++) {
|
|
|
|
|
dayAfterTomorrow[i] = {
|
|
|
|
|
temperature: body.hourly.temperature_2m[48 + i],
|
|
|
|
|
precipitation: body.hourly.precipitation[48 + i],
|
|
|
|
|
apparentTemperature: body.hourly.apparent_temperature[48 + i],
|
|
|
|
|
weatherCode: body.hourly.weather_code[48 + i],
|
|
|
|
|
}
|
|
|
|
|
dayAfterTomorrow[i] = dataAt(body, 48 + i)
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
today,
|
|
|
|
@ -90,18 +89,20 @@ const getDailyData = async () => {
|
|
|
|
|
|
|
|
|
|
const getWeekData = async () => {
|
|
|
|
|
const response = await fetch(
|
|
|
|
|
'https://api.open-meteo.com/v1/forecast?latitude=43.7085&longitude=10.4036&daily=weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,precipitation_sum&timezone=Europe%2FBerlin',
|
|
|
|
|
'https://api.open-meteo.com/v1/forecast?latitude=43.7085&longitude=10.4036&daily=weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,precipitation_sum,precipitation_probability_max&timezone=Europe%2FBerlin',
|
|
|
|
|
)
|
|
|
|
|
const body = await response.json()
|
|
|
|
|
|
|
|
|
|
let week = {}
|
|
|
|
|
for (let i = 0; i < 6; i++) {
|
|
|
|
|
for (let i = 0; i <= 6; i++) {
|
|
|
|
|
week[i] = {
|
|
|
|
|
minimumTemperature: body.daily.temperature_2m_min[i],
|
|
|
|
|
maximumTemperature: body.daily.temperature_2m_max[i],
|
|
|
|
|
minimumApparentTemperature: body.daily.apparent_temperature_min[i],
|
|
|
|
|
maximumApparentTemperature: body.daily.apparent_temperature_max[i],
|
|
|
|
|
precipitationSum: body.daily.precipitation_sum[i],
|
|
|
|
|
precipitationProbabilityMax:
|
|
|
|
|
body.daily.precipitation_probability_max[i],
|
|
|
|
|
weatherCode: body.daily.weather_code[i],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -112,6 +113,7 @@ export default async () => {
|
|
|
|
|
const [daily, week] = await Promise.all([getDailyData(), getWeekData()])
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
format: FORMAT,
|
|
|
|
|
...daily,
|
|
|
|
|
week,
|
|
|
|
|
}
|
|
|
|
|