mirror of
https://github.com/iptv-org/database.git
synced 2025-05-09 19:20:01 -04:00
Update scripts
This commit is contained in:
parent
37b4197fb2
commit
6244ba7adb
54 changed files with 2020 additions and 1145 deletions
23
scripts/commands/db/export.ts
Normal file
23
scripts/commands/db/export.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { DATA_DIR, API_DIR } from '../../constants'
|
||||
import { Storage, File } from '@freearhey/core'
|
||||
import { CSVParser } from '../../core'
|
||||
import { CSVParserRow } from '../../types/csvParser'
|
||||
|
||||
async function main() {
|
||||
const dataStorage = new Storage(DATA_DIR)
|
||||
const apiStorage = new Storage(API_DIR)
|
||||
const parser = new CSVParser()
|
||||
|
||||
const files = await dataStorage.list('*.csv')
|
||||
for (const filepath of files) {
|
||||
const file = new File(filepath)
|
||||
const filename = file.name()
|
||||
const data = await dataStorage.load(file.basename())
|
||||
const parsed = await parser.parse(data)
|
||||
const items = parsed.map((row: CSVParserRow) => row.data)
|
||||
|
||||
await apiStorage.save(`${filename}.json`, items.toJSON())
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue