feat: parse xml from aemet

This commit is contained in:
2026-01-18 13:18:33 +01:00
parent 672ed867a9
commit 06ef233bcc
7 changed files with 152 additions and 38 deletions

View File

@@ -0,0 +1,30 @@
import { Client, Users } from 'node-appwrite';
import { XMLParser } from 'fast-xml-parser';
// This Appwrite function will be executed every time your function is triggered
export default async ({ req, res, log, error }: any) => {
// You can use the Appwrite SDK to interact with other services
// For this example, we're using the Users service
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT ?? '')
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID ?? '')
.setKey(req.headers['x-appwrite-key'] ?? '');
const users = new Users(client);
try {
const response = await fetch('https://www.aemet.es/xml/municipios_h/localidad_h_31019.xml');
if (!response.ok) {
throw new Error(`Error! status: ${response.status}`);
}
const parser = new XMLParser();
let json = parser.parse(await response.text());
log(json)
return res.json({sucess: false, data: json})
} catch(err: any) {
error("Error fetching forecast: " + err.message);
return res.json({success: false, error: err.message})
}
};