Update update-readme.js

This commit is contained in:
Aleksandr Statciuk 2021-10-12 23:09:16 +03:00
parent fdd3105a9f
commit b63b8d79ed

View file

@ -1,27 +1,24 @@
const parser = require('epg-parser')
const markdownInclude = require('markdown-include') const markdownInclude = require('markdown-include')
const path = require('path')
const fs = require('fs')
const countries = require('./countries.json') const countries = require('./countries.json')
const parser = require('./parser')
const file = require('./file') const file = require('./file')
async function main() { async function main() {
console.log('Starting...') console.log('Starting...')
file file
.list('sites/*.channels.xml') .list('.gh-pages/guides/**/*.xml')
.then(files => { .then(files => {
let data = [] let data = []
files.forEach(filename => { files.forEach(filename => {
const channelsFile = file.read(filename) const countryCode = filename.match(/\.gh\-pages\/guides\/(.*)\/.*/i)[1]
const parsed = parser.parseChannels(channelsFile) const country = countries.find(c => c.code === countryCode)
parsed.groups.forEach(group => { const epg = file.read(filename)
const country = countries.find(c => c.code === group.country.toLowerCase()) const parsed = parser.parse(epg)
data.push({ data.push({
countryFlag: country.flag, countryFlag: country.flag,
countryName: country.name, countryName: country.name,
guideUrl: `https://iptv-org.github.io/epg/guides/${country.code}/${parsed.site}.epg.xml`, guideUrl: filename.replace('.gh-pages', 'https://iptv-org.github.io/epg'),
channelCount: group.channels.length channelCount: parsed.channels.length
})
}) })
}) })
@ -35,7 +32,7 @@ async function main() {
const table = generateTable(data, ['Country', 'Channels', 'EPG']) const table = generateTable(data, ['Country', 'Channels', 'EPG'])
file.write('./.readme/_table.md', table) file.write('./.readme/_table.md', table)
generateReadme() markdownInclude.compileFiles('.readme/config.json')
}) })
.finally(() => { .finally(() => {
console.log('Finish') console.log('Finish')
@ -68,9 +65,4 @@ function generateTable(data, header) {
return output return output
} }
function generateReadme() {
console.log('Generating README.md...')
markdownInclude.compileFiles(path.resolve('.readme/config.json'))
}
main() main()