From 3793895948dd07c41fc5966cff7f1111f82e2d94 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 30 Jan 2022 04:37:27 +0300 Subject: [PATCH] Update update-readme.js --- scripts/commands/update-guides.js | 2 +- scripts/commands/update-readme.js | 14 +++++++------- scripts/core/api.js | 8 ++++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/scripts/commands/update-guides.js b/scripts/commands/update-guides.js index 0bbe7c52..1cf00edd 100644 --- a/scripts/commands/update-guides.js +++ b/scripts/commands/update-guides.js @@ -27,7 +27,7 @@ async function generateGuides() { const items = grouped[key] const channels = items .map(i => { - const channel = api.channels.get(i.xmltv_id) + const channel = api.channels.find({ id: i.xmltv_id }) i.name = channel.name i.logo = channel.logo return i diff --git a/scripts/commands/update-readme.js b/scripts/commands/update-readme.js index 2b0d0e17..dcd824c8 100644 --- a/scripts/commands/update-readme.js +++ b/scripts/commands/update-readme.js @@ -1,7 +1,4 @@ -const { file, markdown, parser, logger } = require('../core') -const provinces = require('../data/ca-provinces.json') -const countries = require('../data/countries.json') -const states = require('../data/us-states.json') +const { file, markdown, parser, logger, api } = require('../core') const { program } = require('commander') const _ = require('lodash') @@ -14,6 +11,7 @@ const options = program async function main() { const records = await getLogRecords() + console.log(records) await generateCountriesTable(records) await generateUSStatesTable(records) await generateCanadaProvincesTable(records) @@ -27,7 +25,7 @@ async function generateCountriesTable(items = []) { let rows = [] for (const item of items) { - const country = countries[item.code] + const country = api.countries.find({ code: item.code }) if (!country) continue rows.push({ @@ -51,7 +49,8 @@ async function generateUSStatesTable(items = []) { let rows = [] for (const item of items) { - const state = states[item.code] + if (!item.code.startsWith('US-')) continue + const state = api.subdivisions.find({ code: item.code }) if (!state) continue rows.push({ @@ -74,7 +73,8 @@ async function generateCanadaProvincesTable(items = []) { let rows = [] for (const item of items) { - const province = provinces[item.code] + if (!item.code.startsWith('CA-')) continue + const province = api.subdivisions.find({ code: item.code }) if (!province) continue rows.push({ diff --git a/scripts/core/api.js b/scripts/core/api.js index db9c9160..ae5e1e9b 100644 --- a/scripts/core/api.js +++ b/scripts/core/api.js @@ -1,15 +1,19 @@ +const _ = require('lodash') + class API { constructor(filepath) { this.collection = require(filepath) } - get(id) { - return this.collection.find(c => c.id === id) + find(query) { + return _.find(this.collection, query) } } const api = {} api.channels = new API('../data/channels.json') +api.countries = new API('../data/countries.json') +api.subdivisions = new API('../data/subdivisions.json') module.exports = api