iptv-database/scripts/db/export.js

20 lines
589 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)
const json = await csv.load(filepath).catch(err => {
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()