From df67c3c2c5cc0cd77ced8771c9ca9bc9a19a289c Mon Sep 17 00:00:00 2001 From: bdaneels Date: Mon, 14 Apr 2025 15:43:25 +0200 Subject: [PATCH] add updateResultsDatabase functionality and results.json for storing course results --- iterateOverDashboardTable.js | 2 + utils/results.json | 74 ++++++++++++++++++++++++++++++++++ utils/updateResultsDatabase.js | 39 ++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 utils/results.json create mode 100644 utils/updateResultsDatabase.js diff --git a/iterateOverDashboardTable.js b/iterateOverDashboardTable.js index 421ae71..9446cc0 100644 --- a/iterateOverDashboardTable.js +++ b/iterateOverDashboardTable.js @@ -14,6 +14,7 @@ const wait = require("./wait"); const courseEnrolled = require("./coursesEnrolled"); const parseCourseResults = require('./utils/parseCourseResults'); const config = require("./config.js"); +const updateResultsDatabase = require("./utils/updateResultsDatabase"); async function iterateOverDashboardTable() { /*connection to local host */ @@ -146,6 +147,7 @@ async function iterateOverDashboardTable() { } results.push(result); appendToExcel(result, filename); + updateResultsDatabase(result) } diff --git a/utils/results.json b/utils/results.json new file mode 100644 index 0000000..62066d2 --- /dev/null +++ b/utils/results.json @@ -0,0 +1,74 @@ +[ + { + "LinkNumber": 1, + "StudentName": "William Van Dessel", + "StudentID": "20001044", + "IsCollapsed": "Yes", + "IsCollapsedKeuze": "Yes", + "IsCollapsedMain": "Yes", + "ContainsVZP": "No", + "ContainsVZPKeuze": "No", + "coursesResult": "1010FLWGES Gesch. van de middeleeuwen - 6.00SP, \n1011FLWGES Gesch. van de nieuwe tijd - 6.00SP, \n1014FLWGES Inleiding wereldgeschiedenis - 6.00SP, \n1053FLWGES Hist oef 1 - 6.00SP, ", + "totalStudiepunten": 24 + }, + { + "LinkNumber": 2, + "StudentName": "Joren Van Roy", + "StudentID": "20141999", + "IsCollapsed": "No", + "IsCollapsedKeuze": "Yes", + "IsCollapsedMain": "No", + "ContainsVZP": "No", + "ContainsVZPKeuze": "No", + "coursesResult": "1011FLWGES Gesch. van de nieuwe tijd - 6.00SP, \n1014FLWGES Inleiding wereldgeschiedenis - 6.00SP, \n1300PSWSOC Inleiding tot de Sociologie - 6.00SP, \n1087FLWGES Central and Eastern Europe - 3.00SP, \n1013FLWGES Eigentijdse geschiedenis - 6.00SP, \n1200PSWPOL Inleiding tot de Politicologie - 6.00SP, \n1104TEWVSG Inl. tot het recht - 6.00SP, \n1300PSWSFP Samenleving, feiten, problemen - 6.00SP, \n1302TEWVSG Levensbesch., mens en markt - 3.00SP, ", + "totalStudiepunten": 48 + }, + { + "LinkNumber": 4, + "StudentName": "Zeynep Öcbe", + "StudentID": "20193168", + "IsCollapsed": "No", + "IsCollapsedKeuze": "No", + "IsCollapsedMain": "No", + "ContainsVZP": "No", + "ContainsVZPKeuze": "No", + "coursesResult": "1011FLWGES Gesch. van de nieuwe tijd - 6.00SP, \n1014FLWGES Inleiding wereldgeschiedenis - 6.00SP, \n1053FLWGES Hist oef 1 - 6.00SP, \n1067FLWGES Byzantijnse gesch. - 3.00SP, \n1001IOBGJU Global Justice - 3.00SP, ", + "totalStudiepunten": 24 + }, + { + "LinkNumber": 5, + "StudentName": "Jens Aelbrecht", + "StudentID": "20213047", + "IsCollapsed": "No", + "IsCollapsedKeuze": "Yes", + "IsCollapsedMain": "No", + "ContainsVZP": "No", + "ContainsVZPKeuze": "No", + "coursesResult": "1002FLWGES Inleiding tot de economie - 6.00SP, \n1005FLWGES Oefeningen paleografie - 3.00SP, \n1011FLWGES Gesch. van de nieuwe tijd - 6.00SP, \n1014FLWGES Inleiding wereldgeschiedenis - 6.00SP, \n1053FLWGES Hist oef 1 - 6.00SP, \n1300PSWSOC Sociologie - 6.00SP, \n1054FLWGES Inleiding wijsbegeerte - 6.00SP, \n1067FLWGES Byzantijnse gesch. - 3.00SP, \n1000PSWPUB Publiekrecht - 3.00SP, \n1013FLWGES Eigentijdse geschiedenis - 6.00SP, \n1200PSWPOL Politicologie - 6.00SP, \n1001CPGVKA Levensbeschouwing & wet - 3.00SP, ", + "totalStudiepunten": 60 + }, + { + "LinkNumber": 6, + "StudentName": "Hadi Dagher", + "StudentID": "20221279", + "IsCollapsed": "No", + "IsCollapsedKeuze": "No", + "IsCollapsedMain": "No", + "ContainsVZP": "No", + "ContainsVZPKeuze": "No", + "coursesResult": "1002FLWGES Inleiding tot de economie - 6.00SP, \n1005FLWGES Oefeningen paleografie - 3.00SP, \n1053FLWGES Hist oef 1 - 6.00SP, \n1011FLWGES Gesch. van de nieuwe tijd - 6.00SP, \n1014FLWGES Inleiding wereldgeschiedenis - 6.00SP, ", + "totalStudiepunten": 27 + }, + { + "LinkNumber": 7, + "StudentName": "Casper Janssens", + "StudentID": "20221960", + "IsCollapsed": "No", + "IsCollapsedKeuze": "Yes", + "IsCollapsedMain": "No", + "ContainsVZP": "No", + "ContainsVZPKeuze": "No", + "coursesResult": "1002FLWGES Inleiding tot de economie - 6.00SP, \n1003FLWGES Historische methode - 6.00SP, \n1005FLWGES Oefeningen paleografie - 3.00SP, \n1010FLWGES Gesch. van de middeleeuwen - 6.00SP, \n1011FLWGES Gesch. van de nieuwe tijd - 6.00SP, \n1014FLWGES Inleiding wereldgeschiedenis - 6.00SP, \n1053FLWGES Hist oef 1 - 6.00SP, \n1000RECPOL Politicologie - 3.00SP, \n1300PSWSOC Sociologie - 6.00SP, \n1000RECGPR Geschiedenis privaatrecht - 6.00SP, \n1200RECTEN Taalgebruik Engels - 3.00SP, ", + "totalStudiepunten": 57 + } +] \ No newline at end of file diff --git a/utils/updateResultsDatabase.js b/utils/updateResultsDatabase.js new file mode 100644 index 0000000..1ea4705 --- /dev/null +++ b/utils/updateResultsDatabase.js @@ -0,0 +1,39 @@ +const fs = require("fs"); +const path = require("path"); + +const resultsFilePath = path.join(__dirname, "results.json"); + +// Flag to track if the file has been reset +let isFileReset = false; + +function updateResultsDatabase(newResult) { + // Check if the file needs to be reset + if (!isFileReset) { + if (fs.existsSync(resultsFilePath)) { + const fileContent = fs.readFileSync(resultsFilePath, "utf-8"); + if (fileContent.trim()) { + // Reset the file to an empty array + fs.writeFileSync(resultsFilePath, JSON.stringify([], null, 2)); + console.log("Old data removed from results.json."); + } + } + isFileReset = true; // Mark the file as reset + } + + // Read existing results or initialize an empty array + let results = []; + if (fs.existsSync(resultsFilePath)) { + const fileContent = fs.readFileSync(resultsFilePath, "utf-8"); + if (fileContent.trim()) { + results = JSON.parse(fileContent); + } + } + + // Add the new result to the array + results.push(newResult); + + // Write the updated results back to the file + fs.writeFileSync(resultsFilePath, JSON.stringify(results, null, 2)); +} + +module.exports = updateResultsDatabase; \ No newline at end of file