feat: implement Open-Meteo weather integration with backfill scripts and updated lake data models.
continuous-integration/drone/push Build encountered an error
continuous-integration/drone/push Build encountered an error
This commit is contained in:
+19
-3
@@ -112,11 +112,27 @@ async function scrapeLake(lakeId: string, oid: string, internalId: string) {
|
||||
}
|
||||
|
||||
if (records.length > 0) {
|
||||
// Apply current values to the latest record
|
||||
records[0].inflow = currentInflow;
|
||||
records[0].volume = currentVolume;
|
||||
if (currentTemp !== null) records[0].temperature = currentTemp;
|
||||
if (currentPrecip !== null) records[0].precipitation = currentPrecip;
|
||||
|
||||
// Override weather from PVL completely using Open-Meteo
|
||||
const config = lakesConfig.find(l => l.id.split('|')[0] === internalId);
|
||||
if (config && config.coords) {
|
||||
try {
|
||||
const lat = config.coords[0];
|
||||
const lon = config.coords[1];
|
||||
const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t=temperature_2m,precipitation`;
|
||||
const weatherRes = await axios.get(url, { timeout: 5000 });
|
||||
if (weatherRes.data && weatherRes.data.current) {
|
||||
records[0].temperature = weatherRes.data.current.temperature_2m;
|
||||
records[0].precipitation = weatherRes.data.current.precipitation;
|
||||
}
|
||||
// Small delay to prevent API rate limits
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
} catch (err: any) {
|
||||
console.error(`Failed to fetch weather for ${internalId}:`, err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let existingData: DataRecord[] = [];
|
||||
|
||||
Reference in New Issue
Block a user