From 458e9ce7d7507667d2e01c97101f5a8f87b12d6a Mon Sep 17 00:00:00 2001 From: Martin Velebil Date: Tue, 27 May 2025 22:02:52 +0200 Subject: [PATCH] further changes --- .gitignore | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++ app.js | 93 +++++++++++++++++++++++------------- 2 files changed, 198 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index a6c57f5..ae9aca2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,139 @@ +application-key.json +.idea/ *.json +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# vitepress build output +**/.vitepress/dist + +# vitepress cache directory +**/.vitepress/cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* diff --git a/app.js b/app.js index 47a6e7a..f4c2a3e 100644 --- a/app.js +++ b/app.js @@ -4,47 +4,49 @@ import {google} from "googleapis"; // Emoji name mapping - add your aliases as needed const NAME_ALIASES = { // 🙃 aliases - 'Vrouba von Vrbicz': '🙃', - 'Vróbič': '🙃', - 'Vrba Vrbička': '🙃', - 'Jirka V.': '🙃', + 'vrouba von vrbicz': '🙃', + 'vróbič': '🙃', + 'vrba vrbička': '🙃', + 'jirka v.': '🙃', // 👨‍🏭 aliases - 'Párek z Mourkova': '👨‍🏭', - 'Marek': '👨‍🏭', - 'Mourek': '👨‍🏭', - 'Mourek (jen láhve)': '👨‍🏭', + 'párek z mourkova': '👨‍🏭', + 'marek': '👨‍🏭', + 'mourek': '👨‍🏭', + 'mourek (jen láhve)': '👨‍🏭', // 🤒 aliases - 'Kruzík Ruzický': '🤒', - 'Kruzík Ruzík': '🤒', + 'kruzík ruzický': '🤒', + 'kruzík ruzík': '🤒', + 'krouzič': '🤒', // 🤑 aliases - 'Matuzalém Kremžský': '🤑', - 'Matuzalém I/II.': '🤑', - 'Matúš': '🤑', + 'matuzalém kremžský': '🤑', + 'matuzalém i/ii.': '🤑', + 'matúš': '🤑', // 😎 aliases 'martin': '😎', - 'Martin Brony Veleblil': '😎', - 'Veleblil Bobajz z Broníkova': '😎', - 'Bronos': '😎', + 'martin brony veleblil': '😎', + 'veleblil bobajz z broníkova': '😎', + 'bronos': '😎', // 🤯 aliases 'ja': '🤯', - 'Kuba': '🤯', - 'Kuba-Buba': '🤯', - "d'Artakuba Zlominoha": '🤯', - 'Kuba Zlominoha': '🤯', + 'kuba': '🤯', + 'kuba-buba': '🤯', + "d'artakuba zlominoha": '🤯', + 'kuba zlominoha': '🤯', // 😴 aliases - 'Sam': '😴', - 'Ditrpich von Šalina': '😴', + 'sam': '😴', + 'ditrpich von šalina': '😴', // 🍖 aliases - 'Šunka Šunkovič Šunkovský': '🍖', - 'Šunka Pražský': '🍖', - 'Šunkovič': '🍖', + 'šunka šunkovič šunkovský': '🍖', + 'šunka pražský': '🍖', + 'šunkovič': '🍖', + 'dan': '🍖', // Default for unrecognized aliases 'default': 'Ostatní' @@ -58,7 +60,7 @@ const spreadsheetId = '1RxeQTnirJILgqXDuvI2RQt9vljn1Jz_JFCzVDRQviIg'; // Create a reusable sheets API client async function createSheetsClient() { const auth = new google.auth.GoogleAuth({ - keyFile: 'epic-c381a-c7475e0b43cc.json', + keyFile: 'application-key.json', scopes: ['https://www.googleapis.com/auth/spreadsheets'], }); @@ -112,9 +114,26 @@ async function getSplidData(splidCode) { expensesAndPayments, groupInfo ); - const suggestedPayments = SplidClient.getSuggestedPayments(balance); - return balance; + // Create a map of member IDs to their names/initials + const memberMap = {}; + for (const member of members) { + memberMap[member.GlobalId] = { + name: member.name, + emoji: getNameFromAlias(member.name) + }; + } + + // Enhance the balance object with member information + const enhancedBalance = {}; + for (const [memberId, balanceInfo] of Object.entries(balance)) { + enhancedBalance[memberId] = { + ...balanceInfo, + memberInfo: memberMap[memberId] || { name: 'Unknown', emoji: NAME_ALIASES['default'] } + }; + } + + return enhancedBalance; } async function resetTableData() { @@ -133,21 +152,29 @@ async function resetTableData() { } async function main() { - const splidCodes = await getSheetData(spreadsheetId, 'Splidy!C2:C'); - const userTags = await getSheetData(spreadsheetId, 'Splidy!E1:M1'); + const userTags = await getSheetData(spreadsheetId, 'Splidy!E1:M1'); // Get header row as array console.log(splidCodes); await resetTableData(); - for (const splidCode of splidCodes) { - const splidCodeString = splidCode[0]; + for (let i = 0; i < splidCodes.length; i++) { + const splidCodeString = splidCodes[i][0]; if (!splidCodeString) { continue; } console.log(`Processing Splid code: ${splidCodeString}`); const balance = await getSplidData(splidCodeString); - console.log(balance); + + const rowData = []; + + for (const tag of userTags[0]) { + const memberEntry = Object.entries(balance).find(([_, info]) => info.memberInfo.emoji === tag); + rowData.push(memberEntry ? memberEntry[1].balance : '-'); + } + + // Update the sheet with the row data + await updateSheetData(spreadsheetId, `Splidy!E${i+2}:M${i+2}`, [rowData]); } }