diff --git a/functions/aemet/README.md b/functions/aemet/README.md index 80cc15e..b126631 100644 --- a/functions/aemet/README.md +++ b/functions/aemet/README.md @@ -1,47 +1,12 @@ -# aemet +# Aemet +Endpoint to get forecast summary to use with battery heater. -## 🧰 Usage +https://697361d50005d83da5ca.functions.app.fosil.eu/ -### GET /ping +# Deployment -- Returns a "Pong" message. +Login: +appwrite login --endpoint "https://app.fosil.eu/v1" -**Response** - -Sample `200` Response: - -```text -Pong -``` - -### GET, POST, PUT, PATCH, DELETE / - -- Returns a "Learn More" JSON response. - -**Response** - -Sample `200` Response: - -```json -{ - "motto": "Build like a team of hundreds_", - "learn": "https://appwrite.io/docs", - "connect": "https://appwrite.io/discord", - "getInspired": "https://builtwith.appwrite.io" -} -``` - -## ⚙️ Configuration - -| Setting | Value | -| ----------------- | ------------- | -| Runtime | Bun (1.0) | -| Entrypoint | `src/main.ts` | -| Build Commands | `bun install` | -| Permissions | `any` | -| Timeout (Seconds) | 15 | -| Scopes | `users.read` | - -## 🔒 Environment Variables - -No environment variables required. +Deploy: +appwrite client --project-id="696bbb680032fc5192c9" && appwrite functions create-deployment --function-id=69736073000fadb92a9f --code="." --activate=true diff --git a/functions/aemet/bun.lock b/functions/aemet/bun.lock index 8c04091..2857a79 100644 --- a/functions/aemet/bun.lock +++ b/functions/aemet/bun.lock @@ -10,9 +10,12 @@ "typescript": "^5.4.5", }, "devDependencies": { - "@types/bun": "^1.1.16", + "@types/bun": "^1.3.6", "prettier": "^3.2.5", }, + "peerDependencies": { + "typescript": "^5", + }, }, }, "packages": { diff --git a/functions/aemet/package.json b/functions/aemet/package.json index 0342011..048378c 100644 --- a/functions/aemet/package.json +++ b/functions/aemet/package.json @@ -13,7 +13,11 @@ "typescript": "^5.4.5" }, "devDependencies": { - "@types/bun": "^1.1.16", + "@types/bun": "^1.3.6", "prettier": "^3.2.5" + }, + "private": true, + "peerDependencies": { + "typescript": "^5" } } diff --git a/functions/aemet/src/main.ts b/functions/aemet/src/main.ts index 480253b..58d8217 100644 --- a/functions/aemet/src/main.ts +++ b/functions/aemet/src/main.ts @@ -16,16 +16,19 @@ export default async ({ req, res, log, error }: any) => { throw new Error(`Error! status: ${response.status}`); } - const decoder = new TextDecoder('iso-8859-1'); // It should be iso-8859-15 but Bum v1.1 does not support it. + const decoder = new TextDecoder('windows-1252'); // It should be iso-8859-15 but Bum v1.1 does not support it. let xml = decoder.decode(await response.arrayBuffer()) - const parser = new XMLParser(); + const options = { + attributeNamePrefix: "", + ignoreAttributes: false + }; + const parser = new XMLParser(options); let json = parser.parse(xml); - log(json.root.prediccion) - return res.json({ sucess: true, data: json.root.prediccion }) - - } catch(err: any) { + let currentDay = json.root.prediccion.dia[0] + return res.json({ sucess: true, data: currentDay }) + } catch (err: any) { error("Error fetching forecast: " + err.message); - return res.json({success: false, error: err.message}) + return res.json({ success: false, error: err.message }) } }; diff --git a/functions/aemet/tsconfig.json b/functions/aemet/tsconfig.json new file mode 100644 index 0000000..bfa0fea --- /dev/null +++ b/functions/aemet/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + // Environment setup & latest features + "lib": ["ESNext"], + "target": "ESNext", + "module": "Preserve", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +}