added precipitation probability for OpenMeteo

main
Fran314 4 weeks ago
parent 9032a38706
commit 0aec1d5a75

@ -173,6 +173,10 @@ Format:
"type": "number", "type": "number",
"unit": "mm" "unit": "mm"
}, },
"precipitationProbability": {
"type": "number",
"unit": "%"
},
"apparentTemperature": { "apparentTemperature": {
"type": "number", "type": "number",
"unit": "°C" "unit": "°C"

@ -13,7 +13,12 @@ const opts = process.env.ON_NIX ? NIX_OPS : {}
const run = async () => { const run = async () => {
const browser = await puppeteer.launch(opts) const browser = await puppeteer.launch(opts)
const [iLMeteo, treBmeteo, openMeteo] = await Promise.all([ const [
// Comment out unwanted fields
iLMeteo,
treBmeteo,
openMeteo,
] = await Promise.all([
fetchILMeteo(browser), fetchILMeteo(browser),
fetch3Bmeteo(browser), fetch3Bmeteo(browser),
fetchOpenMeteo(), fetchOpenMeteo(),
@ -22,9 +27,9 @@ const run = async () => {
await browser.close() await browser.close()
return { return {
// iLMeteo, iLMeteo,
treBmeteo, treBmeteo,
// openMeteo, openMeteo,
} }
} }

@ -8,6 +8,10 @@ const FORMAT = {
type: 'number', type: 'number',
unit: 'mm', unit: 'mm',
}, },
precipitationProbability: {
type: 'number',
unit: '%',
},
apparentTemperature: { apparentTemperature: {
type: 'number', type: 'number',
unit: '°C', unit: '°C',
@ -47,39 +51,34 @@ const FORMAT = {
const getDailyData = async () => { const getDailyData = async () => {
const response = await fetch( 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() const body = await response.json()
let today = {} const dataAt = (body, i) => {
const startTime = new Date().getHours() + 1 return {
for (let i = startTime; i <= 23; i++) {
today[i] = {
temperature: body.hourly.temperature_2m[i], temperature: body.hourly.temperature_2m[i],
precipitation: body.hourly.precipitation[i], precipitation: body.hourly.precipitation[i],
precipitationProbability: body.hourly.precipitation_probability[i],
apparentTemperature: body.hourly.apparent_temperature[i], apparentTemperature: body.hourly.apparent_temperature[i],
weatherCode: body.hourly.weather_code[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 = {} let tomorrow = {}
for (let i = 0; i <= 23; i++) { for (let i = 0; i <= 23; i++) {
tomorrow[i] = { tomorrow[i] = dataAt(body, 24 + 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],
}
} }
let dayAfterTomorrow = {} let dayAfterTomorrow = {}
for (let i = 0; i <= 23; i++) { for (let i = 0; i <= 23; i++) {
dayAfterTomorrow[i] = { dayAfterTomorrow[i] = dataAt(body, 48 + 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],
}
} }
return { return {
today, today,
@ -90,18 +89,20 @@ const getDailyData = async () => {
const getWeekData = async () => { const getWeekData = async () => {
const response = await fetch( 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() const body = await response.json()
let week = {} let week = {}
for (let i = 0; i < 6; i++) { for (let i = 0; i <= 6; i++) {
week[i] = { week[i] = {
minimumTemperature: body.daily.temperature_2m_min[i], minimumTemperature: body.daily.temperature_2m_min[i],
maximumTemperature: body.daily.temperature_2m_max[i], maximumTemperature: body.daily.temperature_2m_max[i],
minimumApparentTemperature: body.daily.apparent_temperature_min[i], minimumApparentTemperature: body.daily.apparent_temperature_min[i],
maximumApparentTemperature: body.daily.apparent_temperature_max[i], maximumApparentTemperature: body.daily.apparent_temperature_max[i],
precipitationSum: body.daily.precipitation_sum[i], precipitationSum: body.daily.precipitation_sum[i],
precipitationProbabilityMax:
body.daily.precipitation_probability_max[i],
weatherCode: body.daily.weather_code[i], weatherCode: body.daily.weather_code[i],
} }
} }
@ -112,6 +113,7 @@ export default async () => {
const [daily, week] = await Promise.all([getDailyData(), getWeekData()]) const [daily, week] = await Promise.all([getDailyData(), getWeekData()])
return { return {
format: FORMAT,
...daily, ...daily,
week, week,
} }

Loading…
Cancel
Save