Update update.js

This commit is contained in:
Aleksandr Statciuk 2022-10-27 19:16:17 +03:00
parent 03cd08b786
commit 3c16d29889

View file

@ -63,8 +63,9 @@ async function main() {
let countryPrograms = db_programs.filter(p => countryChannels.includes(p.channel))
let langGroups = _.groupBy(countryPrograms, 'lang')
let countryLanguages = _.uniq(['eng', ...country.languages])
let countryLanguages = _.uniq([...country.languages, 'eng'])
let programs = {}
for (let langCode of countryLanguages) {
const lang = convertLangCode(langCode, '3', '1')
if (!lang) continue
@ -72,27 +73,31 @@ async function main() {
let langPrograms = langGroups[lang]
if (!langPrograms || !langPrograms.length) continue
let programs = []
let channelGroups = _.groupBy(langPrograms, 'channel')
for (let groupedPrograms of Object.values(channelGroups)) {
for (let channel in channelGroups) {
if (programs[channel]) continue
let groupedPrograms = channelGroups[channel]
let channelPrograms = getChannelPrograms(groupedPrograms)
if (!channelPrograms.length) continue
programs = programs.concat(channelPrograms)
programs[channel] = channelPrograms
}
programs = _.sortBy(programs, ['channel', 'start'])
}
programs = _.flatten(Object.values(programs))
programs = programs = _.sortBy(programs, ['channel', 'start'])
programs = programs.map(p => new Program(p, new Channel(channels_dic[p.channel])))
let channels = programs.map(p => {
let c = channels_dic[p.channel]
c.site = p.site
c.lang = lang
c.lang = p.lang
return new Channel(c)
})
channels = _.sortBy(channels, 'id')
channels = _.uniqBy(channels, 'id')
const filename = `${country.code.toLowerCase()}_${lang}`
const filename = country.code.toLowerCase()
const xmlFilepath = `${PUBLIC_DIR}/guides/${filename}.xml`
const gzFilepath = `${PUBLIC_DIR}/guides/${filename}.xml.gz`
const jsonFilepath = `${PUBLIC_DIR}/guides/${filename}.json`
@ -112,7 +117,7 @@ async function main() {
for (let channel of channels) {
let result = {
country: country.code,
lang,
lang: channel.lang,
site: channel.site,
channel: channel.id,
filename
@ -121,7 +126,6 @@ async function main() {
await file.append(logPath, JSON.stringify(result) + '\r\n')
}
}
}
}
main()