mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update load-cluster.js
This commit is contained in:
parent
ca3913f357
commit
7e5e1f34d3
4 changed files with 13 additions and 26 deletions
|
@ -5,7 +5,6 @@ const { db, logger, timer, file, parser } = require('../core')
|
||||||
|
|
||||||
const options = program
|
const options = program
|
||||||
.requiredOption('-c, --cluster-id <cluster-id>', 'The ID of cluster to load', parser.parseNumber)
|
.requiredOption('-c, --cluster-id <cluster-id>', 'The ID of cluster to load', parser.parseNumber)
|
||||||
.option('--days <days>', 'Number of days for which to grab the program', parser.parseNumber, 1)
|
|
||||||
.option('--delay <delay>', 'Delay between requests (in mileseconds)', parser.parseNumber)
|
.option('--delay <delay>', 'Delay between requests (in mileseconds)', parser.parseNumber)
|
||||||
.option(
|
.option(
|
||||||
'-t, --timeout <timeout>',
|
'-t, --timeout <timeout>',
|
||||||
|
@ -17,19 +16,18 @@ const options = program
|
||||||
.opts()
|
.opts()
|
||||||
|
|
||||||
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
||||||
|
const CLUSTER_PATH = `${LOGS_DIR}/load-cluster/cluster_${options.clusterId}.log`
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
logger.info('Starting...')
|
logger.info('Starting...')
|
||||||
timer.start()
|
timer.start()
|
||||||
|
|
||||||
const clusterLog = `${LOGS_DIR}/load-cluster/cluster_${options.clusterId}.log`
|
|
||||||
logger.info(`Loading cluster: ${options.clusterId}`)
|
logger.info(`Loading cluster: ${options.clusterId}`)
|
||||||
logger.info(`Creating '${clusterLog}'...`)
|
logger.info(`Creating '${CLUSTER_PATH}'...`)
|
||||||
await file.create(clusterLog)
|
await file.create(CLUSTER_PATH)
|
||||||
await db.queue.load()
|
await db.queue.load()
|
||||||
const items = await db.queue.find({ cluster_id: options.clusterId })
|
const items = await db.queue.find({ cluster_id: options.clusterId })
|
||||||
const total = options.days * items.length
|
const total = items.length
|
||||||
logger.info(`Total ${total} requests`)
|
|
||||||
|
|
||||||
logger.info('Loading...')
|
logger.info('Loading...')
|
||||||
const results = {}
|
const results = {}
|
||||||
|
@ -38,7 +36,6 @@ async function main() {
|
||||||
let config = require(file.resolve(item.configPath))
|
let config = require(file.resolve(item.configPath))
|
||||||
|
|
||||||
config = _.merge(config, {
|
config = _.merge(config, {
|
||||||
days: options.days,
|
|
||||||
debug: options.debug,
|
debug: options.debug,
|
||||||
delay: options.delay,
|
delay: options.delay,
|
||||||
request: {
|
request: {
|
||||||
|
@ -46,7 +43,7 @@ async function main() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await grabber.grab(item, config, async (data, err) => {
|
await grabber.grab(item, item.date, config, async (data, err) => {
|
||||||
logger.info(
|
logger.info(
|
||||||
`[${i}/${total}] ${item.site} - ${item.xmltv_id} - ${data.date.format('MMM D, YYYY')} (${
|
`[${i}/${total}] ${item.site} - ${item.xmltv_id} - ${data.date.format('MMM D, YYYY')} (${
|
||||||
data.programs.length
|
data.programs.length
|
||||||
|
@ -56,13 +53,12 @@ async function main() {
|
||||||
if (err) logger.error(err.message)
|
if (err) logger.error(err.message)
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
channel: data.channel,
|
_qid: item._id,
|
||||||
programs: data.programs,
|
programs: data.programs,
|
||||||
date: data.date.format(),
|
|
||||||
error: err ? err.message : null
|
error: err ? err.message : null
|
||||||
}
|
}
|
||||||
|
|
||||||
await file.append(clusterLog, JSON.stringify(result) + '\n')
|
await file.append(CLUSTER_PATH, JSON.stringify(result) + '\n')
|
||||||
|
|
||||||
if (i < total) i++
|
if (i < total) i++
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
{"channel":{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr","bh/chaines-tv.orange.fr"],"cluster_id":1,"programCount":32,"_id":"0Wefq0oMR3feCcuY"},"programs":[],"date":"2022-01-29T00:00:00Z","error":null}
|
{"_qid":"0Wefq0oMR3feCcuY","programs":[],"error":null}
|
||||||
{"channel":{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"programCount":0,"_id":"1XzrxNkSF2AQNBrT"},"programs":[],"date":"2022-01-29T00:00:00Z","error":null}
|
{"_qid":"1XzrxNkSF2AQNBrT","programs":[],"error":null}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"cluster_id":84,"programCount":0,"date":"2022-01-21T00:00:00Z","error":"Invalid header value char","_id":"00AluKCrCnfgrl8W"}
|
{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"cluster_id":84,"date":"2022-01-21T00:00:00Z","_id":"00AluKCrCnfgrl8W"}
|
||||||
{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr", "bh/chaines-tv.orange.fr"],"cluster_id":1,"programCount":32,"date":"2022-01-21T00:00:00Z","error":null,"_id":"0Wefq0oMR3feCcuY"}
|
{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr", "bh/chaines-tv.orange.fr"],"cluster_id":1,"date":"2022-01-21T00:00:00Z","_id":"0Wefq0oMR3feCcuY"}
|
||||||
{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"programCount":0,"date":"2022-01-21T00:00:00Z","error":null,"_id":"1XzrxNkSF2AQNBrT"}
|
{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"date":"2022-01-21T00:00:00Z","_id":"1XzrxNkSF2AQNBrT"}
|
||||||
{"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"cluster_id":120,"programCount":14,"date":"2022-01-21T00:00:00Z","error":null,"_id":"1lnhXpN7g0ER5XwN"}
|
{"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"cluster_id":120,"date":"2022-01-21T00:00:00Z","_id":"1lnhXpN7g0ER5XwN"}
|
||||||
|
|
|
@ -23,15 +23,6 @@ it('can load cluster', () => {
|
||||||
let output = content('tests/__data__/output/logs/load-cluster/cluster_1.log')
|
let output = content('tests/__data__/output/logs/load-cluster/cluster_1.log')
|
||||||
let expected = content('tests/__data__/expected/logs/load-cluster/cluster_1.log')
|
let expected = content('tests/__data__/expected/logs/load-cluster/cluster_1.log')
|
||||||
|
|
||||||
output = output.map(i => {
|
|
||||||
i.date = null
|
|
||||||
return i
|
|
||||||
})
|
|
||||||
expected = expected.map(i => {
|
|
||||||
i.date = null
|
|
||||||
return i
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(output).toEqual(expected)
|
expect(output).toEqual(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue