further changes

This commit is contained in:
Martin Velebil 2025-05-27 22:02:52 +02:00
parent 2481e7cd38
commit 458e9ce7d7
2 changed files with 198 additions and 33 deletions

138
.gitignore vendored
View file

@ -1 +1,139 @@
application-key.json
.idea/
*.json *.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.*

93
app.js
View file

@ -4,47 +4,49 @@ import {google} from "googleapis";
// Emoji name mapping - add your aliases as needed // Emoji name mapping - add your aliases as needed
const NAME_ALIASES = { const NAME_ALIASES = {
// 🙃 aliases // 🙃 aliases
'Vrouba von Vrbicz': '🙃', 'vrouba von vrbicz': '🙃',
'Vróbič': '🙃', 'vróbič': '🙃',
'Vrba Vrbička': '🙃', 'vrba vrbička': '🙃',
'Jirka V.': '🙃', 'jirka v.': '🙃',
// 👨‍🏭 aliases // 👨‍🏭 aliases
'Párek z Mourkova': '👨‍🏭', 'párek z mourkova': '👨‍🏭',
'Marek': '👨‍🏭', 'marek': '👨‍🏭',
'Mourek': '👨‍🏭', 'mourek': '👨‍🏭',
'Mourek (jen láhve)': '👨‍🏭', 'mourek (jen láhve)': '👨‍🏭',
// 🤒 aliases // 🤒 aliases
'Kruzík Ruzický': '🤒', 'kruzík ruzický': '🤒',
'Kruzík Ruzík': '🤒', 'kruzík ruzík': '🤒',
'krouzič': '🤒',
// 🤑 aliases // 🤑 aliases
'Matuzalém Kremžský': '🤑', 'matuzalém kremžský': '🤑',
'Matuzalém I/II.': '🤑', 'matuzalém i/ii.': '🤑',
'Matúš': '🤑', 'matúš': '🤑',
// 😎 aliases // 😎 aliases
'martin': '😎', 'martin': '😎',
'Martin Brony Veleblil': '😎', 'martin brony veleblil': '😎',
'Veleblil Bobajz z Broníkova': '😎', 'veleblil bobajz z broníkova': '😎',
'Bronos': '😎', 'bronos': '😎',
// 🤯 aliases // 🤯 aliases
'ja': '🤯', 'ja': '🤯',
'Kuba': '🤯', 'kuba': '🤯',
'Kuba-Buba': '🤯', 'kuba-buba': '🤯',
"d'Artakuba Zlominoha": '🤯', "d'artakuba zlominoha": '🤯',
'Kuba Zlominoha': '🤯', 'kuba zlominoha': '🤯',
// 😴 aliases // 😴 aliases
'Sam': '😴', 'sam': '😴',
'Ditrpich von Šalina': '😴', 'ditrpich von šalina': '😴',
// 🍖 aliases // 🍖 aliases
'Šunka Šunkovič Šunkovský': '🍖', 'šunka šunkovič šunkovský': '🍖',
'Šunka Pražský': '🍖', 'šunka pražský': '🍖',
'Šunkovič': '🍖', 'šunkovič': '🍖',
'dan': '🍖',
// Default for unrecognized aliases // Default for unrecognized aliases
'default': 'Ostatní' 'default': 'Ostatní'
@ -58,7 +60,7 @@ const spreadsheetId = '1RxeQTnirJILgqXDuvI2RQt9vljn1Jz_JFCzVDRQviIg';
// Create a reusable sheets API client // Create a reusable sheets API client
async function createSheetsClient() { async function createSheetsClient() {
const auth = new google.auth.GoogleAuth({ const auth = new google.auth.GoogleAuth({
keyFile: 'epic-c381a-c7475e0b43cc.json', keyFile: 'application-key.json',
scopes: ['https://www.googleapis.com/auth/spreadsheets'], scopes: ['https://www.googleapis.com/auth/spreadsheets'],
}); });
@ -112,9 +114,26 @@ async function getSplidData(splidCode) {
expensesAndPayments, expensesAndPayments,
groupInfo 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() { async function resetTableData() {
@ -133,21 +152,29 @@ async function resetTableData() {
} }
async function main() { async function main() {
const splidCodes = await getSheetData(spreadsheetId, 'Splidy!C2:C'); 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); console.log(splidCodes);
await resetTableData(); await resetTableData();
for (const splidCode of splidCodes) { for (let i = 0; i < splidCodes.length; i++) {
const splidCodeString = splidCode[0]; const splidCodeString = splidCodes[i][0];
if (!splidCodeString) { if (!splidCodeString) {
continue; continue;
} }
console.log(`Processing Splid code: ${splidCodeString}`); console.log(`Processing Splid code: ${splidCodeString}`);
const balance = await getSplidData(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]);
} }
} }