diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2021-08-16 16:26:01 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2021-08-16 16:26:01 +0200 |
| commit | bf563861320cf207bb2d788f50b327e4eb37016a (patch) | |
| tree | 7e775216592e1f935fd9a10a6cf59f84c789f7c9 /load_spreadsheet.js | |
| parent | 9ae202820b698796f93b929b3e30cd499de796a1 (diff) | |
showing a graph
Diffstat (limited to 'load_spreadsheet.js')
| -rw-r--r-- | load_spreadsheet.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/load_spreadsheet.js b/load_spreadsheet.js new file mode 100644 index 0000000..347c6eb --- /dev/null +++ b/load_spreadsheet.js @@ -0,0 +1,68 @@ +/** + * 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)); |
