aboutsummaryrefslogtreecommitdiff
path: root/update.js
blob: 919fede8402efb5695d1320c33f79fcaccb8cd77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const openFile = require("./Functions/open.js").file;
const parseClasses = require("./parseClasses.js").classes;
const parse = require("./dbparse.js");
const updateExceptions = require('./parseExceptions.js').updateExceptions;

// Run this if you want to build the database from text files
async function buildDB(dbconnection, shiftPath, classPath, exceptionPath) {
	let shiftCont = await openFile(shiftPath);
	shiftCont = shiftCont.toString("utf-8");

	let exceptions = await openFile(exceptionPath);
	exceptions = exceptions.toString("utf-8");

	let classes = await openFile(classPath);
	classes = classes.toString('utf-8');

	await parseClasses(dbconnection, classes);
        await parse.build(shiftCont, dbconnection);
        await updateExceptions(exceptions, dbconnection);

	return 0;
}

exports.update = buildDB;
// Example call:
/*
const openFile = require("./Functions/open.js").file;
const database  = require("./database.js");
const dbcredentials = await openFile("../dblogin.txt");
const DB = new database.Database(JSON.parse(dbcredentials));
await updateDB.update(DB, "./shifts.txt", "./Kurssitarjottimet/2016Classes.txt", "./Kurssitarjottimet/NewClasses.txt");
*/