Created commands/create-database.js

This commit is contained in:
Aleksandr Statciuk
2022-01-06 12:59:37 +03:00
parent 5c95098fea
commit f5dbc9376e
12 changed files with 29999 additions and 1 deletions

31
scripts/core/parser.js Normal file
View File

@@ -0,0 +1,31 @@
const logger = require('./logger')
const file = require('./file')
const grabber = require('epg-grabber')
const parser = {}
parser.parseChannels = async function(filepath) {
const content = await file.read(filepath)
const channels = grabber.parseChannels(content)
return channels
}
parser.parseLogs = async function (filepath) {
const content = await file.read(filepath)
if (!content) return []
const lines = content.split('\n')
return lines.map(line => (line ? JSON.parse(line) : null)).filter(l => l)
}
parser.parseNumber = function (string) {
const parsed = parseInt(string)
if (isNaN(parsed)) {
throw new Error('scripts/core/parser.js:parseNumber() Input value is not a number')
}
return parsed
}
module.exports = parser