Split constants to seperate file

This commit is contained in:
martinshoob 2025-05-28 09:56:35 +02:00
parent 78cb2e9e43
commit e33e3a20c8
2 changed files with 95 additions and 67 deletions

84
app.js
View file

@ -1,69 +1,23 @@
import { SplidClient } from 'splid-js';
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.': '🙃',
// 👨‍🏭 aliases
'párek z mourkova': '👨‍🏭',
'marek': '👨‍🏭',
'mourek': '👨‍🏭',
'mourek (jen láhve)': '👨‍🏭',
// 🤒 aliases
'kruzík ruzický': '🤒',
'kruzík ruzík': '🤒',
'krouzič': '🤒',
// 🤑 aliases
'matuzalém kremžský': '🤑',
'matuzalém i/ii.': '🤑',
'matúš': '🤑',
// 😎 aliases
'martin': '😎',
'martin brony veleblil': '😎',
'veleblil bobajz z broníkova': '😎',
'bronos': '😎',
// 🤯 aliases
'ja': '🤯',
'kuba': '🤯',
'kuba-buba': '🤯',
"d'artakuba zlominoha": '🤯',
'kuba zlominoha': '🤯',
// 😴 aliases
'sam': '😴',
'ditrpich von šalina': '😴',
// 🍖 aliases
'šunka šunkovič šunkovský': '🍖',
'šunka pražský': '🍖',
'šunkovič': '🍖',
'dan': '🍖',
// Default for unrecognized aliases
'default': 'Ostatní'
};
import {
NAME_ALIASES,
SPREADSHEET_ID,
SHEETS_CONFIG,
SHEET_RANGES,
TABLE_RESET_ROW_COUNT,
TABLE_COLUMN_COUNT,
SHEET_ID,
COLUMN_INDICES
} from './constants.js';
function getNameFromAlias(alias) {
return NAME_ALIASES[alias.toLowerCase()] || NAME_ALIASES['default'];
}
const spreadsheetId = '1RxeQTnirJILgqXDuvI2RQt9vljn1Jz_JFCzVDRQviIg';
// Create a reusable sheets API client
async function createSheetsClient() {
const auth = new google.auth.GoogleAuth({
keyFile: 'application-key.json',
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});
const auth = new google.auth.GoogleAuth(SHEETS_CONFIG);
return google.sheets({ version: 'v4', auth });
}
@ -137,14 +91,11 @@ async function getSplidData(splidCode) {
}
async function resetTableData() {
// Define a reasonable number of rows to clear/fill (adjust as needed)
const rowCount = 100;
// Create an array of arrays with "-" for each cell in columns E through L
const dashData = Array(rowCount).fill().map(() => Array(9).fill("-"));
// Create an array of arrays with "-" for each cell
const dashData = Array(TABLE_RESET_ROW_COUNT).fill().map(() => Array(TABLE_COLUMN_COUNT).fill("-"));
try {
await updateSheetData(spreadsheetId, 'Splidy!E2:M', dashData);
await updateSheetData(SPREADSHEET_ID, SHEET_RANGES.DATA_RESET, dashData);
} catch (err) {
console.error('Error resetting table data:', err);
throw err;
@ -152,10 +103,11 @@ async function resetTableData() {
}
async function main() {
const splidCodes = await getSheetData(spreadsheetId, 'Splidy!C2:C');
const userTags = await getSheetData(spreadsheetId, 'Splidy!E1:M1'); // Get header row as array
const splidCodes = await getSheetData(SPREADSHEET_ID, SHEET_RANGES.SPLID_CODES);
const userTags = await getSheetData(SPREADSHEET_ID, SHEET_RANGES.USER_TAGS);
console.log(splidCodes);
console.log("Resetting table data.")
await resetTableData();
for (let i = 0; i < splidCodes.length; i++) {
@ -177,7 +129,7 @@ async function main() {
}
// Update the sheet with the row data
await updateSheetData(spreadsheetId, `Splidy!E${i+2}:M${i+2}`, [rowData]);
await updateSheetData(SPREADSHEET_ID, SHEET_RANGES.DATA_ROW(i), [rowData]);
}
}

76
constants.js Normal file
View file

@ -0,0 +1,76 @@
export const NAME_ALIASES = {
// 🙃 aliases
'vrouba von vrbicz': '🙃',
'vróbič': '🙃',
'vrba vrbička': '🙃',
'jirka v.': '🙃',
// 👨‍🏭 aliases
'párek z mourkova': '👨‍🏭',
'marek': '👨‍🏭',
'mourek': '👨‍🏭',
'mourek (jen láhve)': '👨‍🏭',
// 🤒 aliases
'kruzík ruzický': '🤒',
'kruzík ruzík': '🤒',
'krouzič': '🤒',
// 🤑 aliases
'matuzalém kremžský': '🤑',
'matuzalém i/ii.': '🤑',
'matúš': '🤑',
// 😎 aliases
'martin': '😎',
'martin brony veleblil': '😎',
'veleblil bobajz z broníkova': '😎',
'bronos': '😎',
// 🤯 aliases
'ja': '🤯',
'kuba': '🤯',
'kuba-buba': '🤯',
"d'artakuba zlominoha": '🤯',
'kuba zlominoha': '🤯',
// 😴 aliases
'sam': '😴',
'ditrpich von šalina': '😴',
// 🍖 aliases
'šunka šunkovič šunkovský': '🍖',
'šunka pražský': '🍖',
'šunkovič': '🍖',
'dan': '🍖',
// Default for unrecognized aliases
'default': 'Ostatní'
};
export const SPREADSHEET_ID = '1RxeQTnirJILgqXDuvI2RQt9vljn1Jz_JFCzVDRQviIg';
// Google Sheets configuration
export const SHEETS_CONFIG = {
keyFile: 'application-key.json',
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
};
// Sheet ranges
export const SHEET_RANGES = {
SPLID_CODES: 'Splidy!C2:C',
USER_TAGS: 'Splidy!E1:M1',
DATA_RESET: 'Splidy!E2:M',
DATA_ROW: (rowIndex) => `Splidy!E${rowIndex + 2}:M${rowIndex + 2}`
};
// Other constants
export const TABLE_RESET_ROW_COUNT = 100;
export const TABLE_COLUMN_COUNT = 9; // Columns E through M
export const COLUMN_INDICES = {
E: 4,
M: 12
};
export const SHEET_ID = 0;