1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 19:49:37 +02:00

using open-meteo instead

This commit is contained in:
sylvain.chateau 2024-09-10 22:27:29 +02:00
parent 0cb79a5d3c
commit b234bc16ff

View file

@ -7,27 +7,30 @@ const getExternalWeather = async () => {
// Fetch data from external API // Fetch data from external API
try { try {
const res = await axios.get( const res = await axios.get('https://api.open-meteo.com/v1/forecast', { params: {
`http://api.weatherapi.com/v1/current.json?key=${secret}&q=${lat},${long}` latitude: lat,
); longitude: long,
current: ['is_day', 'temperature_2m', 'relative_humidity_2m', 'cloud_cover', 'wind_speed_10m', 'weathercode'],
} });
// Save weather data // Save weather data
const cursor = res.data.current; const cursor = res.data.current;
const weatherData = await Weather.create({ const weatherData = await Weather.create({
externalLastUpdate: cursor.last_updated, externalLastUpdate: "externalLastUpdate",
tempC: cursor.temp_c, tempC: cursor.temperature_2m, // can not be 0 put like minus kelvin
tempF: cursor.temp_f, tempF: cursor.temperature_2m,
isDay: cursor.is_day, isDay: Boolean(cursor.is_day),
cloud: cursor.cloud, cloud: cursor.cloud_cover,
conditionText: cursor.condition.text, conditionText: "conditionText",
conditionCode: cursor.condition.code, conditionCode: 1,
humidity: cursor.humidity, humidity: cursor.relative_humidity_2m,
windK: cursor.wind_kph, windK: cursor.wind_speed_10m,
windM: cursor.wind_mph, windM: cursor.wind_speed_10m,
}); });
return weatherData; return weatherData;
} catch (err) { } catch (err) {
throw new Error('External API request failed'); throw new Error(err);
//throw new Error('External API request failed');
} }
}; };