Update load-cluster.js

This commit is contained in:
Aleksandr Statciuk 2022-01-16 15:12:38 +03:00
parent 5ab469205c
commit c034f001e8
2 changed files with 17 additions and 28 deletions

View file

@ -46,30 +46,29 @@ async function main() {
} }
}) })
const programs = await grabber.grab(channel, config, async (data, err) => { await grabber.grab(channel, config, async (data, err) => {
await db.channels.update({ _id: channel._id }, { $set: { logo: data.channel.logo } }) await file.append(
clusterLog,
JSON.stringify({
_id: channel._id,
site: channel.site,
country: channel.country,
logo: data.channel.logo,
gid: channel.gid,
programs: data.programs
}) + '\n'
)
logger.info( logger.info(
`[${i}/${total}] ${channel.site} - ${data.id} - ${data.date.format('MMM D, YYYY')} (${ `[${i}/${total}] ${channel.site} - ${channel.xmltv_id} - ${data.date.format(
data.programs.length 'MMM D, YYYY'
} programs)` )} (${data.programs.length} programs)`
) )
if (err) logger.error(err.message) if (err) logger.error(err.message)
if (i < total) i++ if (i < total) i++
}) })
await file.append(
clusterLog,
JSON.stringify({
_id: channel._id,
site: channel.site,
country: channel.country,
gid: channel.gid,
programs
}) + '\n'
)
} }
db.channels.compact() db.channels.compact()

View file

@ -24,6 +24,7 @@ it('can load cluster', () => {
expect(output[0]).toMatchObject({ expect(output[0]).toMatchObject({
_id: '0Wefq0oMR3feCcuY', _id: '0Wefq0oMR3feCcuY',
site: 'chaines-tv.orange.fr', site: 'chaines-tv.orange.fr',
logo: 'https://example.com/logo.png',
country: 'US', country: 'US',
gid: 'fr' gid: 'fr'
}) })
@ -31,21 +32,10 @@ it('can load cluster', () => {
expect(output[1]).toMatchObject({ expect(output[1]).toMatchObject({
_id: '1XzrxNkSF2AQNBrT', _id: '1XzrxNkSF2AQNBrT',
site: 'magticom.ge', site: 'magticom.ge',
logo: 'https://www.magticom.ge/images/channels/MjAxOC8wOS8xMC9lZmJhNWU5Yy0yMmNiLTRkMTAtOWY5Ny01ODM0MzY0ZTg0MmEuanBn.jpg',
country: 'US', country: 'US',
gid: 'ge' gid: 'ge'
}) })
const database = content('tests/__data__/temp/database/channels.db')
expect(database[1]).toMatchObject({
_id: '0Wefq0oMR3feCcuY',
logo: 'https://example.com/logo.png'
})
expect(database[2]).toMatchObject({
_id: '1XzrxNkSF2AQNBrT',
logo: 'https://www.magticom.ge/images/channels/MjAxOC8wOS8xMC9lZmJhNWU5Yy0yMmNiLTRkMTAtOWY5Ny01ODM0MzY0ZTg0MmEuanBn.jpg'
})
}) })
function content(filepath) { function content(filepath) {