Initial commit
This commit is contained in:
commit
e28367573d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
result.txt
|
||||
16
README.md
Normal file
16
README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Generator für HTML zu Projekten und Seminaren
|
||||
|
||||
Als Fachschaft schicken wir kurz vor Beginn eines jeden Semesters eine Email zu allen verfügbaren Seminaren und Projekten mit Beschreibung, Links und Anmeldefristen raus.
|
||||
Die dazu nach und nach eintrudelnden Informationen der verschiedenen Lehrstühle können dank dieses Tools in einer einfachen Tabellendatei gesammelt und dann ganz automatisch daraus generiert werden.
|
||||
|
||||
Hierzu muss das Repository geklont werden. Anschließend sind folgende Schritte notwendig, für die Node.js benötigt wird:
|
||||
|
||||
```bash
|
||||
cd path/to/this/directory
|
||||
node index.js path/to/file.csv
|
||||
```
|
||||
|
||||
Aus der Datei `file.csv` wird automatisiert Markup erstellt, das anschließend im Ordner des Programmes (genau dieser hier) unter `result.txt` zu finden ist.
|
||||
Es kann nach Belieben in VC-Kurse eingebunden werden.
|
||||
Der Dateipfad sollte entweder absolut oder relativ zum Programmordner angegeben werden.
|
||||
Zur Struktur der Quelldatei empfiehlt sich ein Blick in die Dateien ehemaliger Semester in der Cloud.
|
||||
95
index.js
Normal file
95
index.js
Normal file
@ -0,0 +1,95 @@
|
||||
const csv = require('fast-csv')
|
||||
const fs = require('fs')
|
||||
|
||||
let records = []
|
||||
|
||||
/**
|
||||
* Parse CSV file and call processor functions on every line.
|
||||
*/
|
||||
function start (dataFile) {
|
||||
csv
|
||||
.parseFile(dataFile, {
|
||||
delimiter: ';'
|
||||
})
|
||||
.on("data", function (data) {
|
||||
if (data[0] !== 'Bereich') processInput(...data)
|
||||
})
|
||||
.on("end", createHTML)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate one object for every line in the CSV file and push
|
||||
* it to the records array.
|
||||
*/
|
||||
function processInput (section, chair, category, audience, abbreviation,
|
||||
topic, description, deadline, link) {
|
||||
records.push({
|
||||
section, chair, category, audience, abbreviation, topic, description, deadline, link
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate HTML from the records array.
|
||||
* The resulting markup is written to ./result.txt.
|
||||
*/
|
||||
function createHTML() {
|
||||
let resultString = ''
|
||||
const recordsBySection = groupBy(records, x => x.section)
|
||||
|
||||
Array.from(['Informatik', 'Angewandte Informatik', 'Wirtschaftsinformatik'])
|
||||
.forEach(function (section) {
|
||||
if (recordsBySection.has(section)) {
|
||||
resultString += `<h1>${section}</h1>\n`
|
||||
|
||||
let recordsByChair = groupBy(recordsBySection.get(section), x => x.chair)
|
||||
let chairs = [...recordsByChair.keys()].sort()
|
||||
chairs.forEach(function (chair) {
|
||||
resultString += `<h3>${chair}</h3>\n`
|
||||
|
||||
let recordsByCategory = groupBy(recordsByChair.get(chair), x => x.category)
|
||||
let categories = [...recordsByCategory.keys()].sort()
|
||||
categories.forEach(function (category) {
|
||||
|
||||
recordsByCategory.get(category).forEach(function (cur) {
|
||||
resultString += `<div style="border: 1px solid lightgray; box-shadow: 0px 2px 4px rgba(0,0,0,0.3); padding: 1rem; margin-bottom: 1rem;"><h5>${category}`
|
||||
resultString += cur.abbreviation ? ` ${cur.abbreviation}` : ''
|
||||
resultString += `: ${cur.topic} (${cur.audience})</h5>\n`
|
||||
resultString += `<p><strong>Kurzbeschreibung:</strong> ${cur.description}</p>\n`
|
||||
resultString += `<p><strong>Anmeldefrist</strong>: ${cur.deadline}</p>\n`
|
||||
resultString += `<p><strong>Weitere Informationen und Anmeldung:</strong> `
|
||||
resultString += cur.link.startsWith('http') ? `<br/><a href="${cur.link}">${cur.link}</a>` : cur.link
|
||||
resultString += `</p></div>\n`
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
fs.writeFileSync('result.txt', resultString)
|
||||
console.log(`Successfully parsed ${process.argv[2]}.`)
|
||||
}
|
||||
|
||||
if (process.argv[2]) {
|
||||
start(process.argv[2])
|
||||
} else {
|
||||
console.error("Missing argument. You have to pass the name of the data file.")
|
||||
}
|
||||
|
||||
/**
|
||||
* Group an array of records by a given key.
|
||||
* Taken from the answer to this question:
|
||||
* https: //stackoverflow.com/questions/14446511/most-efficient-method-to-groupby-on-an-array-of-objects#38327540
|
||||
*/
|
||||
function groupBy(list, keyGetter) {
|
||||
const map = new Map();
|
||||
list.forEach((item) => {
|
||||
const key = keyGetter(item);
|
||||
const collection = map.get(key);
|
||||
if (!collection) {
|
||||
map.set(key, [item]);
|
||||
} else {
|
||||
collection.push(item);
|
||||
}
|
||||
});
|
||||
return map;
|
||||
}
|
||||
33
package-lock.json
generated
Normal file
33
package-lock.json
generated
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "projekte-und-seminare",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@types/lodash": {
|
||||
"version": "4.14.138",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.138.tgz",
|
||||
"integrity": "sha512-A4uJgHz4hakwNBdHNPdxOTkYmXNgmUAKLbXZ7PKGslgeV0Mb8P3BlbYfPovExek1qnod4pDfRbxuzcVs3dlFLg=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.7.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.3.tgz",
|
||||
"integrity": "sha512-3SiLAIBkDWDg6vFo0+5YJyHPWU9uwu40Qe+v+0MH8wRKYBimHvvAOyk3EzMrD/TrIlLYfXrqDqrg913PynrMJQ=="
|
||||
},
|
||||
"fast-csv": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-csv/-/fast-csv-3.4.0.tgz",
|
||||
"integrity": "sha512-/vPTDJc/l6VLOLIqcrMjuhyi8ZVTipTNl2GkVvaYiHlyh16oQMYPUkUVfREurT3MYE9j3mLQDk2Q8kPq30qQCg==",
|
||||
"requires": {
|
||||
"@types/lodash": "^4.14.132",
|
||||
"@types/node": "^12.0.2",
|
||||
"lodash": "^4.17.13"
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
|
||||
}
|
||||
}
|
||||
}
|
||||
14
package.json
Normal file
14
package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "projekte-und-seminare",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"fast-csv": "^3.4.0"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user