aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <work.joelkronqvist@gmail.com>2022-10-25 18:57:32 +0300
committerJoel Kronqvist <work.joelkronqvist@gmail.com>2022-10-25 18:57:32 +0300
commitbd8e36aec2c6a78594c34066edc34b309cac2e0c (patch)
treeb1a44c2ee85340a115c3dc683c8f02f64a1a119e
parent569fe38f54b21d9b7de5a8b48cbf14987383281d (diff)
downloadLYLLRuoka-bd8e36aec2c6a78594c34066edc34b309cac2e0c.tar.gz
LYLLRuoka-bd8e36aec2c6a78594c34066edc34b309cac2e0c.zip
Fixed shift parsing when no teacher is supplied. Made server be run in a loop in init.sh to bring it up again if it crashes.
-rw-r--r--dbparse.js46
-rwxr-xr-xinit.sh19
2 files changed, 33 insertions, 32 deletions
diff --git a/dbparse.js b/dbparse.js
index 7e8d8fd..f196c78 100644
--- a/dbparse.js
+++ b/dbparse.js
@@ -108,36 +108,36 @@ async function writeShift(weekday, shiftId, shiftLine, courseLine, DB)
);
// Shift contents
- const courseRegex = /(?:[a-ö]{2,3}\d{2,3} ?\+? ?)+ [a-ö]{4}/gi;
+ const courseRegex = /([A-ZÅÄÖ]{2,3}\d{2,3})(?:\+([A-ZÅÄÖ]{2,3}\d{2,3}))?(?: ([A-ZÅÄÖ]{4}))?/gi;
const courses = courseLine.matchAll(courseRegex);
for(const course of courses)
{
- const _lastSpace = course[0].lastIndexOf(" ");
- const courseNames = course[0].substring(0, _lastSpace).split(/ ?\+ ?/);
- const teacherName = course[0].substring(_lastSpace + 1);
-
- // For loop is needed, because some courses are marked like KE16+KE26 MATI
- async function handleCourse(courseName, teacherName)
- {
- let className = await DB.execute(
- "SELECT class FROM classes WHERE course=?",
- [courseName]
- );
- className = className[0];
- if (className !== undefined)
- className = className.class;
- else
- className = null;
-
+ const courseName1 = course[1];
+ const courseName2 = course[2]; // this exists if the course is like MA11+MA12 RIHO
+ const teacher = course[3] || null;
+
+ // Get the class
+ let className = await DB.execute(
+ "SELECT class FROM classes WHERE course=?",
+ [courseName]
+ );
+ if (className !== undefined)
+ className = className.class;
+ else
+ className = null;
+ className = className[0];
+
+ // Add the info
+ dbOperations.push(DB.execute(
+ `INSERT IGNORE INTO shifts VALUES (${weekday}, ${shiftId}, ?, ?, ?)`,
+ [courseName1, teacher, className]
+ ));
+ if (courseName2 !== null) {
dbOperations.push(DB.execute(
`INSERT IGNORE INTO shifts VALUES (${weekday}, ${shiftId}, ?, ?, ?)`,
- [courseName, teacherName, className]
+ [courseName2, teacher, className]
));
}
- for(const courseName of courseNames)
- {
- dbOperations.push(handleCourse(courseName, teacherName));
- }
}
await Promise.all(dbOperations);
diff --git a/init.sh b/init.sh
index 2fc915d..5fb171f 100755
--- a/init.sh
+++ b/init.sh
@@ -1,8 +1,7 @@
#!/bin/sh
-exec 1>>/tmp/slogs
-exec 2>>/tmp/slogs
-echo "========"
-echo | date
+exec 1>>/var/slogs
+exec 2>>/var/slogs
+echo ""
echo "# Init running"
echo "# Waiting for connection..."
@@ -22,9 +21,11 @@ echo "# Database seems to be available (ignore error messages above)"
echo ""
cd "$BASE_DIR/LYLLRuoka"
-echo "# node server.js:"
-node server.js
+while echo "# node server.js:"; do
+ node server.js
-echo "========"
-echo ""
-echo ""
+ # Sleep below, so that the loop can't cause too big a load to the server, if the server terminates very fast.
+ sleep 5
+ echo "SERVER TERMINATED!"
+ echo "--------"
+done