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 countryPrograms = db_programs.filter(p => countryChannels.includes(p.channel))
let langGroups = _.groupBy(countryPrograms, 'lang') let langGroups = _.groupBy(countryPrograms, 'lang')
let countryLanguages = _.uniq(['eng', ...country.languages]) let countryLanguages = _.uniq([...country.languages, 'eng'])
let programs = {}
for (let langCode of countryLanguages) { for (let langCode of countryLanguages) {
const lang = convertLangCode(langCode, '3', '1') const lang = convertLangCode(langCode, '3', '1')
if (!lang) continue if (!lang) continue
@ -72,27 +73,31 @@ async function main() {
let langPrograms = langGroups[lang] let langPrograms = langGroups[lang]
if (!langPrograms || !langPrograms.length) continue if (!langPrograms || !langPrograms.length) continue
let programs = []
let channelGroups = _.groupBy(langPrograms, 'channel') 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) let channelPrograms = getChannelPrograms(groupedPrograms)
if (!channelPrograms.length) continue 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]))) programs = programs.map(p => new Program(p, new Channel(channels_dic[p.channel])))
let channels = programs.map(p => { let channels = programs.map(p => {
let c = channels_dic[p.channel] let c = channels_dic[p.channel]
c.site = p.site c.site = p.site
c.lang = lang c.lang = p.lang
return new Channel(c) return new Channel(c)
}) })
channels = _.sortBy(channels, 'id') channels = _.sortBy(channels, 'id')
channels = _.uniqBy(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 xmlFilepath = `${PUBLIC_DIR}/guides/${filename}.xml`
const gzFilepath = `${PUBLIC_DIR}/guides/${filename}.xml.gz` const gzFilepath = `${PUBLIC_DIR}/guides/${filename}.xml.gz`
const jsonFilepath = `${PUBLIC_DIR}/guides/${filename}.json` const jsonFilepath = `${PUBLIC_DIR}/guides/${filename}.json`
@ -112,7 +117,7 @@ async function main() {
for (let channel of channels) { for (let channel of channels) {
let result = { let result = {
country: country.code, country: country.code,
lang, lang: channel.lang,
site: channel.site, site: channel.site,
channel: channel.id, channel: channel.id,
filename filename
@ -122,7 +127,6 @@ async function main() {
} }
} }
} }
}
main() main()