Created
January 6, 2026 09:56
-
-
Save ey-ron/7f4cdb74bfd0fc893aa43dc723405e4b to your computer and use it in GitHub Desktop.
code.gs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const CONFIG = { | |
| sheet_Retirement: "Retirement Plan", | |
| sheet_Spends: "Statement - Spends", | |
| sheet_Investment: "Investments", | |
| sheet_Assets: "Assets", | |
| sheet_Goals: "Savings Goals", | |
| sheet_Budget: "Budget & Expense", | |
| timezone: Session.getScriptTimeZone() | |
| }; | |
| // ========================================== | |
| // ROUTING | |
| // ========================================== | |
| function doGet(e) { | |
| const route = (e && e.parameter && e.parameter.page) ? e.parameter.page : 'exchangerate'; | |
| switch (route) { | |
| case 'dashboard': | |
| return db_loadDashboard(); | |
| case 'dashb': | |
| return dashb_load(); | |
| case 'exchangerate': | |
| return ex_loadExchangeRatePage(); | |
| case 'widgyhome': | |
| return api_getWidgyHome(); | |
| case 'dash': | |
| return mock_loadDashboard(); | |
| default: | |
| return HtmlService.createHtmlOutput("<h3>Page not found.</h3>"); | |
| } | |
| } | |
| // ========================================== | |
| // ROUTING (POST) | |
| // ========================================== | |
| function doPost(e) { | |
| var output = {}; | |
| try { | |
| var data = JSON.parse(e.postData.contents); | |
| var action = data.action; | |
| switch (action) { | |
| case 'log_spend': | |
| return api_logSpend(data); | |
| case 'update_budget': | |
| return _sendJSON({status: "error", message: "Not implemented yet"}); | |
| default: | |
| return _sendJSON({status: "error", message: "Unknown action: " + action}); | |
| } | |
| } catch (err) { | |
| return _sendJSON({status: "error", message: "Invalid JSON or Server Error: " + err.message}); | |
| } | |
| } | |
| // Helper to standardise JSON responses | |
| function _sendJSON(object) { | |
| return ContentService.createTextOutput(JSON.stringify(object)) | |
| .setMimeType(ContentService.MimeType.JSON); | |
| } | |
| // ========================================== | |
| // HTML TEMPLATE HELPER | |
| // ========================================== | |
| function include(filename) { | |
| return HtmlService.createHtmlOutputFromFile(filename).getContent(); | |
| } | |
| /** | |
| * Fetches the live market price from Yahoo Finance. | |
| * Usage: =YAHOOPRICE("CNDX.L") | |
| */ | |
| function YAHOOPRICE(ticker) { | |
| try { | |
| const url = `https://query1.finance.yahoo.com/v8/finance/chart/${ticker}`; | |
| const response = UrlFetchApp.fetch(url, { muteHttpExceptions: true }); | |
| const json = JSON.parse(response.getContentText()); | |
| // Path to the current market price in Yahoo's JSON | |
| const price = json.chart.result[0].meta.regularMarketPrice; | |
| return price; | |
| } catch (e) { | |
| return "Error: " + e.message; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment