Compare commits
2 commits
78cb2e9e43
...
b897fd5e5c
Author | SHA1 | Date | |
---|---|---|---|
b897fd5e5c | |||
e33e3a20c8 |
2 changed files with 135 additions and 68 deletions
125
app.js
125
app.js
|
@ -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 { google } from "googleapis";
|
||||
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,25 +91,54 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
async function autoResizeColumns(spreadsheetId, sheetId, startColumnIndex, endColumnIndex) {
|
||||
try {
|
||||
const sheets = await createSheetsClient();
|
||||
|
||||
const request = {
|
||||
spreadsheetId: spreadsheetId,
|
||||
resource: {
|
||||
requests: [
|
||||
{
|
||||
autoResizeDimensions: {
|
||||
dimensions: {
|
||||
sheetId: sheetId,
|
||||
dimension: 'COLUMNS',
|
||||
startIndex: startColumnIndex,
|
||||
endIndex: endColumnIndex + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const response = await sheets.spreadsheets.batchUpdate(request);
|
||||
console.log('Columns auto-resized successfully');
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
console.error('Error auto-resizing columns:', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
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 +160,15 @@ 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]);
|
||||
}
|
||||
|
||||
console.log("Sheets updated, adjusting column width.")
|
||||
|
||||
try {
|
||||
await autoResizeColumns(SPREADSHEET_ID, SHEET_ID, COLUMN_INDICES.E, COLUMN_INDICES.M);
|
||||
} catch (err) {
|
||||
console.error('Failed to auto-resize columns, but data was updated successfully:', err);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
76
constants.js
Normal file
76
constants.js
Normal 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;
|
Loading…
Reference in a new issue