diff options
author | JoelHMikael <joel.h.kronqvist@gmail.com> | 2022-02-13 11:53:15 +0200 |
---|---|---|
committer | JoelHMikael <joel.h.kronqvist@gmail.com> | 2022-02-13 11:53:15 +0200 |
commit | 082f9f1b428e13c7a60d588f7d215beff937ffcf (patch) | |
tree | 3647e5448b5be22424e04fad6360b04527738d61 | |
parent | b0841da93712d2bd7d8c47930cb8bed41ce417db (diff) | |
download | LYLLRuoka-082f9f1b428e13c7a60d588f7d215beff937ffcf.tar.gz LYLLRuoka-082f9f1b428e13c7a60d588f7d215beff937ffcf.zip |
Finished README.md instructions
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | README.md | 59 | ||||
-rw-r--r-- | parseClasses.js | 2 | ||||
-rw-r--r-- | shifts.txt | 115 | ||||
-rw-r--r-- | update.js | 8 |
5 files changed, 63 insertions, 126 deletions
@@ -1,4 +1,7 @@ Classes node_modules package-lock.json -shifts.txt
\ No newline at end of file +shifts.txt +Cont/Images/back.xcf +Cont/Images/help.xcf +.vscode
\ No newline at end of file @@ -9,9 +9,9 @@ git clone "https://github.com/JoelHMikael/FoodJS.git" ## Install node.js (16.x, the one in Ubuntus package repositories is outdated) ``` -apt install curl +sudo apt install curl curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - -apt-get install -y nodejs +sudo apt-get install -y nodejs ``` Install npm packages required for project ``` @@ -20,13 +20,13 @@ npm install mysql2 ## Install MySQL server & configure it ``` -apt install mysql-server +sudo apt install mysql-server sudo mysql_secure_installation ``` > Note: If you want to update the databases remotely, you can allow logging in from the local network. In this case you of course have to use a strong password. ## Initializing the database -Log into mysql and run the following to initialize the tables: +If you don't have a backup of the database and need to initialize it, log into mysql and run the following to initialize the tables: ``` CREATE DATABASE lyllruoka; USE lyllruoka; @@ -53,7 +53,7 @@ CREATE TABLE devs ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(30) NOT NULL, description VARCHAR(128), - contact VARCHAR(40) + contact VARCHAR(40) DEFAULT '' ); CREATE TABLE stats ( start DATE PRIMARY KEY, @@ -68,13 +68,58 @@ CREATE TABLE exams ( PRIMARY KEY (start, end) ); ``` +> Note that if you had some information in a former database that you don't update manually, it will be lost. ## Give the server the credentials, keys & other required things * MySQL credentials in `../dblogin.txt` - * You may want to create a user for this. There has been some problems logging in as root on ubuntu, if I remember right. + * You probably should [create a user](https://dev.mysql.com/doc/refman/8.0/en/create-user.html) and [grant privileges to it](https://dev.mysql.com/doc/refman/8.0/en/grant.html) for this. For me logging in as root didn't work out of the box, except of course combined with `sudo`, which does neither work out of the box with node.js. + * The credentials should be in json format. For instance: + ``` + { + "host": "localhost", + "user": "exampleuser", + "password": "password123", + "database": "lyllruoka" + } + ``` * SSL certificate in `../Certificate/key.pem` and `../Certificate/cert.pem` + * As on the [website of node.js](https://nodejs.org/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server/), you can create a self-signed certificate (for testing purposes) as following: + ``` + openssl genrsa -out key.pem + openssl req -new -key key.pem -out csr.pem + openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem + rm csr.pem + ``` --- # Updating the tables -Coming soon...
\ No newline at end of file + +## Shifts and classes +This is an example on how to update the shifts and classes to the database, so that the server can serve them to the clients. + +Lets assume the following filesystem that contains also all of the server code: +``` +shifts.txt +Classes +| oldclasses.txt +| newclasses.txt +``` +Where shifts.txt contains the shifts, `oldclasses.txt` contains the classes of the old curriculum and `newclasses` the classes of the new learning curriculum. + +You can get the shifts from junu's food shift message through Wilma. The classes should be tab delimited text files. You can get them easily by copy-pasting them from the eg. LibreOffice from "Kurssitarjottimet". Provide only the classes of one period, not all of them. + +Then just run the following code in node.js: +``` +const updateDB = require("./update.js"); +const openFile = require("./Functions/open.js").file; +const dbcredentials = await openFile("../dblogin.txt"); +await updateDB.update("./shifts.txt", ["./Classes/oldclasses.txt", "./Classes/newclasses.txt"], dbcredentials); +``` + +## Updating the developer table +Updating the developer table is pretty straightforward. You just need to provide the name of the developer, a description (eg. "Improved the performance of the server") and contact information: +``` +INSERT INTO devs (name, description, contact) VALUES ('[name]', '[description]', '[contact]'); +``` +> Insert the values in the quotation marks, don't change the text before the `VALUES` keyword.
\ No newline at end of file diff --git a/parseClasses.js b/parseClasses.js index 170b63d..ffd8e7f 100644 --- a/parseClasses.js +++ b/parseClasses.js @@ -1,4 +1,4 @@ -const open = require("./open.js"); +const open = require("./Functions/open.js"); const parse = require("./dbparse.js"); const fs = require("fs"); const readline = require("readline"); diff --git a/shifts.txt b/shifts.txt deleted file mode 100644 index 2a6f98d..0000000 --- a/shifts.txt +++ /dev/null @@ -1,115 +0,0 @@ -MAANANTAISIN - -RUOKAILUVUORO I: ruokailu klo 10.50 – 11.30, oppitunti klo 11.40 – 13.00 - -LI16 ANSA, KU61 REOJ, MU101 MAMY, MU111 MAMY, FY51 JUMA, UE26 JSAL, MA84 RIHO, RB21 SASA, EA97 VIHU, FD91 MASI ja KAHDEN TUTKINNON OPINNOT 1., 2. ja 3. VUOSITASON RYHMÄT - - - -RUOKAILUVUORO II: ruokailu klo 11.40 – 12.20, oppitunti klo 11.00 – 11.40 ja klo 12.20 – 13.00 - -PS21 TEKE, BI42 HEIH, HI62 JUSA, EA55 ANLE, FY82 SALE, PS113 SATU, HI33 JAJU ja RB92 MAOI - - - -RUOKAILUVUORO III: ruokailu klo 12.20 – 13.00, oppitunti klo 11.00 – 12.20 - -BI24 LAMI, ÄI94 HAPA, LI11 JUHO, ÄI23+ÄI33 TUTA, HI14 HEAH, YH15 ALMA, YH13 ALMA, ENA27 SABE ja RUB127 ANSU - - - - - -TIISTAISIN - - - -RUOKAILUVUORO I: ruokailu klo 10.50 – 11.20, oppitunti klo 11.30 – 12.50 - -LP23 JUHO, UE23 ALMA, ÄI71 HAPA, SC91 SABE, FY112 SALE, MB94 SAKO, HI34 JUSA ja ÄI95 TUTA - - - -RUOKAILUVUORO II: ruokailu klo 11.40 – 12.10, oppitunti klo 11.00 – 11.40 ja klo 12.10 – 12.50 - -MA81 MATI, EA54 ANLE, YH36 HEAH, BI27 LAMI, MB54 JOTO, BI13 PAHO, BI14 PAHO, ÄI24 VETU ja ÄI34 VETU - - - -RUOKAILUVUORO III: ruokailu klo 12.20 – 12.50, oppitunti klo 11.00 – 12.20 - -LT24 ANSA, ENA21 MASI, ENA22 KAHU, ENA25 VIHU, GE16 HEIH, GE12 HEIH, MU17 MAMY, RUB121 MAOI, RUB122 ANSU, RUB125 KAHU ja RUA21 SASA - - - -KESKIVIIKKOISIN - - - -RUOKAILUVUORO I: ruokailu klo 10.50 – 11.30, oppitunti klo 11.40 – 13.00 - -LI12 ANSA, UE71 SATU, ET71 SATU, ÄI41 TUTA, KU131 REOJ, MKU1 MAOI, BI103 PAHO, FY81 JUMA, ÄI93 MIAU, PS112 JSAL, HI92 JUSA, PC91 VIHU ja PD91 VIHU - - - -RUOKAILUVUORO II: ruokailu klo 11.40 – 12.20, oppitunti klo 11.00 – 11.40 ja klo 12.20 – 13.00 - -ENA24 ANLE, MAA24 + MAA34 MATI, MAB23 ESRI, MAA25 + MAA35 SALE, MA83 SAKO, FI26 TEKE ja RUB124 KAHU - - - -RUOKAILUVUORO III: ruokailu klo 12.20 – 13.00, oppitunti klo 11.00 – 12.20 - -LI13 JUHO, ÄI21 + ÄI31 VETU, RB42 ANSU, EA102 MASI, HI24 HEAH ja EA57 SABE - - - - - -TORSTAISIN - - - -RUOKAILUVUORO I: ruokailu klo 10.50 – 11.20, oppitunti klo 11.30 – 12.50 - -BI32 HEIH, RB43 MAOI, HI71 JUSA, FY52 ESRI, EA56 KAHU, MU23 MAMY, RB131 ANSU ja RA131 ANSU - - - -RUOKAILUVUORO II: ruokailu klo 11.40 – 12.10, oppitunti klo 11.00 – 11.40 ja klo 12.10 – 12.50 - -HI41 JAJU, ÄI26 + ÄI36 TUTA, ÄI21 TUTA, ÄI25 + ÄI35 MIAU, MAA21 + MAA31 JUMA, MAA22 + MAA32 SAKO ja MAA23 + MAA33 RIHO - - - -RUOKAILUVUORO III: ruokailu klo 12.20 – 12.50, oppitunti klo 11.00 – 12.20 - -UE21 JUNU, LI71 JUHO, LP71 JUHO, LT71 JUHO, GE102 PAHO, KE62 SAHE, YH53 HEAH, TE42 ANSA, UE61 SATU ja ÄI97 VETU - - - - - -PERJANTAISIN - - - -RUOKAILUVUORO I: ruokailu klo 10.50 – 11.30, oppitunti klo 11.40 – 13.00 - -FI21 JSAL, EA52 ANLE, MU31 MAMY, MA181 SAKO, MB111 SAHE, MA182 MATI, MB112 RIHO, MB113 JOTO ja ÄI96 MIAU - - - -RUOKAILUVUORO II: ruokailu klo 11.40 – 12.20, oppitunti klo 11.00 – 11.40 ja klo 12.20 – 13.00 - -ÄI22 + ÄI32 HAPA, ENA23 VIHU, FY14 + FY24 ESRI, FY15 + FY25 SALE, ENA26 SABE, KE17 + KE27 OLNU, FY12 ESRI, ÄI23 HAPA, RUB123 ANSU ja RUB126 MAOI - - - -RUOKAILUVUORO III: ruokailu klo 12.20 – 13.00, oppitunti klo 11.00 – 12.20 - -YH11 JAJU, YH12 JAJU, YH33 JUSA, PS72 KAMA, GE22 HEIH, KU24 REOJ, YH37 ALMA, MA191 JUMA ja FD51 MASI - - - -
\ No newline at end of file @@ -1,5 +1,5 @@ const database = require("./database.js"); -const openFile = require("./open.js").file; +const openFile = require("./Functions/open.js").file; const parseClasses = require("./parseClasses.js").classes; const parse = require("./dbparse.js"); @@ -18,4 +18,8 @@ async function buildDB(shiftfile = "./shifts.txt", classfile = "./classes.txt", exports.update = buildDB; // Example call: -// await updateDB.update("./shifts.txt", ["./Kurssitarjottimet/2016Classes.txt", "./Kurssitarjottimet/NewClasses.txt"], dbcredentials);
\ No newline at end of file +/* +const openFile = require("./Functions/open.js").file; +const dbcredentials = openFile("../dblogin.txt"); +await updateDB.update("./shifts.txt", ["./Kurssitarjottimet/2016Classes.txt", "./Kurssitarjottimet/NewClasses.txt"], dbcredentials); +*/
\ No newline at end of file |