iptv-database/scripts/db/export.js

20 lines
593 B
JavaScript
Raw Normal View History

2022-02-13 22:12:11 -05:00
const { csv, file, logger } = require('../core')
const chalk = require('chalk')
2022-02-11 21:55:50 -05:00
const DATA_DIR = process.env.DATA_DIR || './data'
2022-02-13 22:12:11 -05:00
const OUTPUT_DIR = process.env.OUTPUT_DIR || './.api'
2022-02-11 21:55:50 -05:00
2022-02-11 22:29:23 -05:00
async function main() {
const files = await file.list(`${DATA_DIR}/*.csv`)
2022-02-13 22:12:11 -05:00
for (const filepath of files) {
const filename = file.getFilename(filepath)
2022-02-17 09:33:32 -05:00
const json = await csv.fromFile(filepath).catch(err => {
2022-02-13 22:12:11 -05:00
logger.error(chalk.red(`\n${err.message} (${filepath})`))
process.exit(1)
})
await file.create(`${OUTPUT_DIR}/${filename}.json`, JSON.stringify(json))
2022-02-11 21:55:50 -05:00
}
2022-02-11 22:29:23 -05:00
}
main()