mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update update-readme.js
This commit is contained in:
parent
074f4c9357
commit
1a33b7d78d
3 changed files with 37 additions and 37 deletions
|
@ -1,14 +1,11 @@
|
||||||
const { file, markdown, parser, logger } = require('../core')
|
const { file, markdown, parser, logger } = require('../core')
|
||||||
|
const provinces = require('../data/ca-provinces.json')
|
||||||
const countries = require('../data/countries.json')
|
const countries = require('../data/countries.json')
|
||||||
const states = require('../data/us-states.json')
|
const states = require('../data/us-states.json')
|
||||||
const provinces = require('../data/ca-provinces.json')
|
|
||||||
const { program } = require('commander')
|
const { program } = require('commander')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
||||||
const LOG_PATH = `${LOGS_DIR}/update-guides.log`
|
|
||||||
|
|
||||||
let log = []
|
|
||||||
|
|
||||||
const options = program
|
const options = program
|
||||||
.option('-c, --config <config>', 'Set path to config file', '.readme/config.json')
|
.option('-c, --config <config>', 'Set path to config file', '.readme/config.json')
|
||||||
|
@ -16,31 +13,28 @@ const options = program
|
||||||
.opts()
|
.opts()
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await setUp()
|
const records = await getLogRecords()
|
||||||
|
await generateCountriesTable(records)
|
||||||
await generateCountriesTable()
|
await generateUSStatesTable(records)
|
||||||
await generateUSStatesTable()
|
await generateCanadaProvincesTable(records)
|
||||||
await generateCanadaProvincesTable()
|
|
||||||
|
|
||||||
await updateReadme()
|
await updateReadme()
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
async function generateCountriesTable() {
|
async function generateCountriesTable(items = []) {
|
||||||
logger.info('Generating countries table...')
|
logger.info('Generating countries table...')
|
||||||
|
|
||||||
const items = log.filter(i => i.gid.length === 2)
|
|
||||||
let rows = []
|
let rows = []
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const code = item.gid.toUpperCase()
|
const country = countries[item.code]
|
||||||
const country = countries[code]
|
if (!country) continue
|
||||||
|
|
||||||
rows.push({
|
rows.push({
|
||||||
flag: country.flag,
|
flag: country.flag,
|
||||||
name: country.name,
|
name: country.name,
|
||||||
channels: item.count,
|
channels: item.count,
|
||||||
epg: `<code>https://iptv-org.github.io/epg/guides/${item.gid}/${item.site}.epg.xml</code>`
|
epg: `<code>https://iptv-org.github.io/epg/guides/${item.group}.epg.xml</code>`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,19 +46,18 @@ async function generateCountriesTable() {
|
||||||
await file.create('./.readme/_countries.md', table)
|
await file.create('./.readme/_countries.md', table)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateUSStatesTable() {
|
async function generateUSStatesTable(items = []) {
|
||||||
logger.info('Generating US states table...')
|
logger.info('Generating US states table...')
|
||||||
|
|
||||||
const items = log.filter(i => i.gid.startsWith('us-'))
|
|
||||||
let rows = []
|
let rows = []
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const code = item.gid.toUpperCase()
|
const state = states[item.code]
|
||||||
const state = states[code]
|
if (!state) continue
|
||||||
|
|
||||||
rows.push({
|
rows.push({
|
||||||
name: state.name,
|
name: state.name,
|
||||||
channels: item.count,
|
channels: item.count,
|
||||||
epg: `<code>https://iptv-org.github.io/epg/guides/${item.gid}/${item.site}.epg.xml</code>`
|
epg: `<code>https://iptv-org.github.io/epg/guides/${item.group}.epg.xml</code>`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,19 +69,18 @@ async function generateUSStatesTable() {
|
||||||
await file.create('./.readme/_us-states.md', table)
|
await file.create('./.readme/_us-states.md', table)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateCanadaProvincesTable() {
|
async function generateCanadaProvincesTable(items = []) {
|
||||||
logger.info('Generating Canada provinces table...')
|
logger.info('Generating Canada provinces table...')
|
||||||
|
|
||||||
const items = log.filter(i => i.gid.startsWith('ca-'))
|
|
||||||
let rows = []
|
let rows = []
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const code = item.gid.toUpperCase()
|
const province = provinces[item.code]
|
||||||
const province = provinces[code]
|
if (!province) continue
|
||||||
|
|
||||||
rows.push({
|
rows.push({
|
||||||
name: province.name,
|
name: province.name,
|
||||||
channels: item.count,
|
channels: item.count,
|
||||||
epg: `<code>https://iptv-org.github.io/epg/guides/${item.gid}/${item.site}.epg.xml</code>`
|
epg: `<code>https://iptv-org.github.io/epg/guides/${item.group}.epg.xml</code>`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,11 +100,19 @@ async function updateReadme() {
|
||||||
await markdown.compile(options.config)
|
await markdown.compile(options.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setUp() {
|
async function getLogRecords() {
|
||||||
log = await parser.parseLogs(LOG_PATH)
|
const logPath = `${LOGS_DIR}/update-guides.log`
|
||||||
|
const records = await parser.parseLogs(logPath)
|
||||||
|
|
||||||
if (!log.length) {
|
if (!records.length) {
|
||||||
logger.error(`File "${LOG_PATH}" is empty`)
|
logger.error(`File "${logPath}" is empty`)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return records.map(item => {
|
||||||
|
const code = item.group.split('/')[0] || ''
|
||||||
|
item.code = code.toUpperCase()
|
||||||
|
|
||||||
|
return item
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{"gid":"us","site":"magticom.ge","count":74,"status":1}
|
{"group":"us/magticom.ge","count":74}
|
||||||
{"gid":"za","site":"dstv.com","count":1,"status":1}
|
{"group":"za/dstv.com","count":1}
|
||||||
{"gid":"us-pr","site":"tvtv.us","count":14,"status":1}
|
{"group":"us-pr/tvtv.us","count":14}
|
||||||
{"gid":"us-pr","site":"gatotv.com","count":7,"status":1}
|
{"group":"us-pr/gatotv.com","count":7}
|
||||||
{"gid":"us-pr","site":"directv.com","count":1,"status":1}
|
{"group":"us-pr/directv.com","count":1}
|
||||||
{"gid":"ca-nl","site":"tvtv.us","count":1,"status":1}
|
{"group":"ca-nl/tvtv.us","count":1}
|
||||||
{"gid":"us","site":"tvtv.us","count":372,"status":1}
|
{"group":"us/tvtv.us","count":372}
|
||||||
|
|
|
@ -6,7 +6,7 @@ beforeEach(() => {
|
||||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||||
fs.mkdirSync('tests/__data__/output')
|
fs.mkdirSync('tests/__data__/output')
|
||||||
|
|
||||||
execSync(
|
const stdout = execSync(
|
||||||
'LOGS_DIR=tests/__data__/input/logs node scripts/commands/update-readme.js --config=tests/__data__/input/_readme.json',
|
'LOGS_DIR=tests/__data__/input/logs node scripts/commands/update-readme.js --config=tests/__data__/input/_readme.json',
|
||||||
{ encoding: 'utf8' }
|
{ encoding: 'utf8' }
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue