Files
epg/scripts/commands/readme/update.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-02-26 23:21:44 +03:00
const { file, markdown, parser, logger, api, table } = require('../../core')
2022-01-14 23:57:03 +03:00
const { program } = require('commander')
const _ = require('lodash')
2022-10-26 04:41:43 +03:00
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
2022-01-15 18:27:19 +03:00
2022-01-14 23:57:03 +03:00
const options = program
2022-10-22 04:35:11 +03:00
.option('-c, --config <config>', 'Set path to config file', '.readme/readme.json')
2022-01-14 23:57:03 +03:00
.parse(process.argv)
.opts()
async function main() {
2022-05-09 12:58:01 +03:00
await api.countries.load().catch(console.error)
2022-10-26 04:41:43 +03:00
const logPath = `${LOGS_DIR}/guides/update.log`
2023-01-08 12:21:02 +03:00
let log = await parser.parseLogs(logPath)
2023-01-09 10:45:37 +03:00
await createTable(log)
2023-01-08 12:21:02 +03:00
await updateReadme()
}
main()
2023-01-09 10:45:37 +03:00
async function createTable(log) {
let files = _.uniqBy(log, i => i.site + i.channel).reduce((acc, curr) => {
if (!acc[curr.filename]) {
acc[curr.filename] = {
site: curr.site,
lang: curr.lang,
channels: 0,
filename: curr.filename
2023-01-08 12:21:02 +03:00
}
2023-01-09 10:45:37 +03:00
}
2023-01-08 12:21:02 +03:00
2023-01-09 10:45:37 +03:00
acc[curr.filename].channels++
2023-01-08 12:21:02 +03:00
2023-01-09 10:45:37 +03:00
return acc
}, {})
2023-01-08 12:21:02 +03:00
let data = []
for (const filename in files) {
const item = files[filename]
data.push([
item.site,
item.lang,
item.channels,
2023-01-09 10:45:37 +03:00
`<code>https://iptv-org.github.io/epg/guides/${filename}.xml</code>`,
`<a href="https://github.com/iptv-org/epg/actions/workflows/${filename}.yml"><img src="https://github.com/iptv-org/epg/actions/workflows/${filename}.yml/badge.svg" alt="${filename}" style="max-width: 100%;"></a>`
2023-01-08 12:21:02 +03:00
])
}
data = _.orderBy(
data,
[item => item[0], item => (item[1] === 'en' ? Infinity : item[2])],
['asc', 'desc']
)
data = data.map(i => {
i.splice(1, 1)
return i
})
data = Object.values(_.groupBy(data, item => item[0]))
2023-01-09 11:07:34 +03:00
const output = table.create(data, [
'Site',
'Channels',
'EPG',
'Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
])
2023-01-08 12:21:02 +03:00
2023-01-09 10:45:37 +03:00
await file.create('./.readme/_sites.md', output)
2022-01-14 23:57:03 +03:00
}
async function updateReadme() {
2022-02-03 06:22:42 +03:00
logger.info('updating readme.md...')
2022-01-14 23:57:03 +03:00
const config = require(file.resolve(options.config))
await file.createDir(file.dirname(config.build))
await markdown.compile(options.config)
}