Update core/api.js

This commit is contained in:
Aleksandr Statciuk 2022-01-30 05:50:38 +03:00
parent e293add009
commit 146079dc90
8 changed files with 1926 additions and 7 deletions

View file

@ -2,7 +2,6 @@ const { db, logger, file, api } = require('../core')
const grabber = require('epg-grabber')
const _ = require('lodash')
const DB_DIR = process.env.DB_DIR || 'scripts/database'
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
const LOG_PATH = `${LOGS_DIR}/update-guides.log`
@ -21,6 +20,7 @@ async function generateGuides() {
logger.info('Loading "database/programs.db"...')
await db.programs.load()
await api.channels.load()
for (const key in grouped) {
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`

View file

@ -10,6 +10,8 @@ const options = program
.opts()
async function main() {
await api.countries.load()
await api.subdivisions.load()
const records = await getLogRecords()
await generateCountriesTable(records)
await generateUSStatesTable(records)

View file

@ -1,8 +1,16 @@
const _ = require('lodash')
const file = require('./file')
const DATA_DIR = process.env.DATA_DIR || './scripts/data'
class API {
constructor(filepath) {
this.collection = require(filepath)
this.filepath = file.resolve(filepath)
}
async load() {
const data = await file.read(this.filepath)
this.collection = JSON.parse(data)
}
find(query) {
@ -12,8 +20,8 @@ class API {
const api = {}
api.channels = new API('../data/channels.json')
api.countries = new API('../data/countries.json')
api.subdivisions = new API('../data/subdivisions.json')
api.channels = new API(`${DATA_DIR}/channels.json`)
api.countries = new API(`${DATA_DIR}/countries.json`)
api.subdivisions = new API(`${DATA_DIR}/subdivisions.json`)
module.exports = api