/** * Load the No.6092 datasheet into the OKCMS JSON */ import { loadJSON, loadCSV, writeJSON } from "./file_utils.js"; const datasheetFile = "./data_store/tags.csv"; const dbFile = "./db.json"; var tagTypes = [ "No6092", "1620s", "painting", "blunt", "National Gallery of Canada", "AGO", "courtauld", "intervensions", "connosieurship", "double agent", "forensics", "black box", ]; async function main() { // basically this script exists to assign the X'd fields from the spreadsheet // to the okcms json :) const data = await loadCSV(datasheetFile); const db = await loadJSON(dbFile); db.page = db.page || []; db.ui = db.ui || []; // index existing DB entries by ID in case we must merge again const pageById = db.page.reduce((lookup, page) => { const pageId = parseInt(page.id.split("_")[1]); lookup[pageId] = page; return lookup; }, {}); // loop over the CSV data :) data.forEach((row, index) => { const cell = pageById[index] || { __index: index, id: "post_" + index, title: row.Title, }; // loop over the tags... let tagIndex = 0; tagTypes.forEach((type, tagId) => { if (row[type] === "x") { cell["tag_" + tagIndex] = tagId + 1; tagIndex += 1; } }); // make sure all other tags are cleared out for (; tagIndex < 9; tagIndex++) { cell["tag_" + tagIndex] = 0; } if (!pageById[index]) { db.page.push(cell); } }); await writeJSON(dbFile, db); } main().then(() => process.exit(0));