mirror of
https://github.com/iptv-org/database.git
synced 2024-12-21 23:40:23 -05:00
Update export.js
This commit is contained in:
parent
3ff44c3fab
commit
722f167fbb
1 changed files with 8 additions and 16 deletions
|
@ -1,23 +1,15 @@
|
|||
const { csv } = require('../core')
|
||||
const path = require('path')
|
||||
const glob = require('glob')
|
||||
const fs = require('fs')
|
||||
const { csv, file } = require('../core')
|
||||
|
||||
const DATA_DIR = process.env.DATA_DIR || './data'
|
||||
const OUTPUT_DIR = process.env.OUTPUT_DIR || './.gh-pages'
|
||||
|
||||
fs.exists(OUTPUT_DIR, function (exists) {
|
||||
if (!exists) {
|
||||
fs.mkdirSync(OUTPUT_DIR)
|
||||
}
|
||||
})
|
||||
|
||||
glob(`${DATA_DIR}/*.csv`, async function (err, files) {
|
||||
async function main() {
|
||||
const files = await file.list(`${DATA_DIR}/*.csv`)
|
||||
for (const inputFile of files) {
|
||||
const inputFilename = path.parse(inputFile).name
|
||||
const outputFile = `${OUTPUT_DIR}/${inputFilename}.json`
|
||||
|
||||
const inputFilename = file.getFilename(inputFile)
|
||||
const json = await csv.load(inputFile)
|
||||
fs.writeFileSync(path.resolve(outputFile), JSON.stringify(json))
|
||||
await file.create(`${OUTPUT_DIR}/${inputFilename}.json`, JSON.stringify(json))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue