mirror of
https://github.com/Sternenlabor/csv-to-fabaccess-user-toml.git
synced 2025-03-12 06:51:41 +01:00
༼ つ ◕_◕ ༽つ initial commit
This commit is contained in:
commit
3c97e3a831
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
*.csv
|
||||||
|
|
||||||
|
*.toml
|
||||||
|
|
||||||
|
package-lock.json
|
9
.prettierrc.json
Normal file
9
.prettierrc.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"trailingComma": "none",
|
||||||
|
"tabWidth": 4,
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"singleAttributePerLine": false,
|
||||||
|
"html.format.wrapLineLength": 0,
|
||||||
|
"printWidth": 900
|
||||||
|
}
|
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
converts a VereinOnline user CSV export to a FabAccess user.toml
|
20
package.json
Normal file
20
package.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "csv-to-fabaccess-user-toml",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "VereinOnline CSV to FabACcess user.toml",
|
||||||
|
"homepage": "https://www.sternenlabor.de/",
|
||||||
|
"main": "run.mjs",
|
||||||
|
"author": "André Fiedler",
|
||||||
|
"license": "CC0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/Sternenlabor/csv-to-fabaccess-user-toml/issues"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node run.mjs"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@iarna/toml": "^2.2.5",
|
||||||
|
"csv-parser": "^3.0.0",
|
||||||
|
"iconv-lite": "^0.6.3"
|
||||||
|
}
|
||||||
|
}
|
67
run.mjs
Normal file
67
run.mjs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import csv from 'csv-parser'
|
||||||
|
import fs from 'fs'
|
||||||
|
import iconv from 'iconv-lite'
|
||||||
|
import toml from '@iarna/toml'
|
||||||
|
|
||||||
|
const DEFAULT_PASSWORD = 'secret'
|
||||||
|
|
||||||
|
const users = {
|
||||||
|
Admin1: {
|
||||||
|
roles: ['Admin'],
|
||||||
|
passwd: 'secret'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readCSV(filePath) {
|
||||||
|
const results = []
|
||||||
|
|
||||||
|
const stream = fs
|
||||||
|
.createReadStream(filePath)
|
||||||
|
.pipe(iconv.decodeStream('iso-8859-1'))
|
||||||
|
.pipe(
|
||||||
|
csv({
|
||||||
|
separator: ';'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
for await (const record of stream) {
|
||||||
|
results.push(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGroups(u) {
|
||||||
|
let groups = u.Gruppen.split(', ')
|
||||||
|
groups = groups.filter((item) => item !== 'Mitglieder-Infos')
|
||||||
|
return ['User', ...groups]
|
||||||
|
}
|
||||||
|
|
||||||
|
readCSV('./Mitgliederliste.csv')
|
||||||
|
.then((results) => {
|
||||||
|
console.log(results)
|
||||||
|
let userCounter = 0
|
||||||
|
|
||||||
|
for (const u of results) {
|
||||||
|
if (u.Login == '') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
users[u.Login] = {
|
||||||
|
roles: getGroups(u),
|
||||||
|
passwd: DEFAULT_PASSWORD
|
||||||
|
}
|
||||||
|
|
||||||
|
userCounter++
|
||||||
|
}
|
||||||
|
|
||||||
|
const tomlContent = toml.stringify(users)
|
||||||
|
|
||||||
|
fs.promises
|
||||||
|
.writeFile('user.toml', tomlContent)
|
||||||
|
.then(() => console.log('File created successfully'))
|
||||||
|
.catch((err) => console.error('Failed to create file', err))
|
||||||
|
|
||||||
|
console.log('users:', userCounter)
|
||||||
|
})
|
||||||
|
.catch((err) => console.error(err))
|
Loading…
x
Reference in New Issue
Block a user