mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Validate Guides
This commit is contained in:
parent
92c20a7232
commit
f21ae7f646
4 changed files with 49 additions and 5 deletions
41
scripts/commands/guides/validate.js
Normal file
41
scripts/commands/guides/validate.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
const { db, logger, api } = require('../../core')
|
||||
const chalk = require('chalk')
|
||||
|
||||
async function main() {
|
||||
await api.channels.load()
|
||||
await api.guides.load()
|
||||
logger.info('loading database/programs.db...')
|
||||
await db.programs.load()
|
||||
let db_programs = await db.programs.find({})
|
||||
logger.info(`found ${db_programs.length} programs`)
|
||||
|
||||
const stats = {
|
||||
files: 0,
|
||||
errors: 0
|
||||
}
|
||||
const errors = []
|
||||
let api_channels = await api.channels.all()
|
||||
|
||||
api_channels.forEach(channel => {
|
||||
let programs = db_programs.filter(p => p.channel == channel.id)
|
||||
if (programs.length > 0) {
|
||||
if (!api.guides.find({ channel: channel.id })) {
|
||||
errors.push({ type: 'no_guide', xmltv_id: channel.id, ...channel })
|
||||
stats.errors++
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (errors.length) {
|
||||
console.table(errors, ['type', 'xmltv_id', 'name', 'country'])
|
||||
console.log()
|
||||
stats.files++
|
||||
}
|
||||
|
||||
if (stats.errors > 0) {
|
||||
logger.error(chalk.red(`${stats.errors} error(s)`))
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue