mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update core/api.js
This commit is contained in:
parent
e293add009
commit
146079dc90
8 changed files with 1926 additions and 7 deletions
|
@ -2,7 +2,6 @@ const { db, logger, file, api } = require('../core')
|
||||||
const grabber = require('epg-grabber')
|
const grabber = require('epg-grabber')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
const DB_DIR = process.env.DB_DIR || 'scripts/database'
|
|
||||||
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
||||||
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
||||||
const LOG_PATH = `${LOGS_DIR}/update-guides.log`
|
const LOG_PATH = `${LOGS_DIR}/update-guides.log`
|
||||||
|
@ -21,6 +20,7 @@ async function generateGuides() {
|
||||||
|
|
||||||
logger.info('Loading "database/programs.db"...')
|
logger.info('Loading "database/programs.db"...')
|
||||||
await db.programs.load()
|
await db.programs.load()
|
||||||
|
await api.channels.load()
|
||||||
|
|
||||||
for (const key in grouped) {
|
for (const key in grouped) {
|
||||||
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
|
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
|
||||||
|
|
|
@ -10,6 +10,8 @@ const options = program
|
||||||
.opts()
|
.opts()
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
await api.countries.load()
|
||||||
|
await api.subdivisions.load()
|
||||||
const records = await getLogRecords()
|
const records = await getLogRecords()
|
||||||
await generateCountriesTable(records)
|
await generateCountriesTable(records)
|
||||||
await generateUSStatesTable(records)
|
await generateUSStatesTable(records)
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
const file = require('./file')
|
||||||
|
|
||||||
|
const DATA_DIR = process.env.DATA_DIR || './scripts/data'
|
||||||
|
|
||||||
class API {
|
class API {
|
||||||
constructor(filepath) {
|
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) {
|
find(query) {
|
||||||
|
@ -12,8 +20,8 @@ class API {
|
||||||
|
|
||||||
const api = {}
|
const api = {}
|
||||||
|
|
||||||
api.channels = new API('../data/channels.json')
|
api.channels = new API(`${DATA_DIR}/channels.json`)
|
||||||
api.countries = new API('../data/countries.json')
|
api.countries = new API(`${DATA_DIR}/countries.json`)
|
||||||
api.subdivisions = new API('../data/subdivisions.json')
|
api.subdivisions = new API(`${DATA_DIR}/subdivisions.json`)
|
||||||
|
|
||||||
module.exports = api
|
module.exports = api
|
||||||
|
|
55
tests/__data__/input/data/channels.json
Normal file
55
tests/__data__/input/data/channels.json
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "BravoEast.us",
|
||||||
|
"name": "Bravo East",
|
||||||
|
"network": null,
|
||||||
|
"country": "US",
|
||||||
|
"subdivision": null,
|
||||||
|
"city": null,
|
||||||
|
"broadcast_area": [
|
||||||
|
"c/US"
|
||||||
|
],
|
||||||
|
"languages": [
|
||||||
|
"eng"
|
||||||
|
],
|
||||||
|
"categories": [],
|
||||||
|
"is_nsfw": false,
|
||||||
|
"logo": "https://www.directv.com/images/logos/channels/dark/large/579.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "CNNInternationalEurope.us",
|
||||||
|
"name": "CNN International Europe",
|
||||||
|
"network": null,
|
||||||
|
"country": "US",
|
||||||
|
"subdivision": null,
|
||||||
|
"city": null,
|
||||||
|
"broadcast_area": [
|
||||||
|
"r/EUR"
|
||||||
|
],
|
||||||
|
"languages": [
|
||||||
|
"eng"
|
||||||
|
],
|
||||||
|
"categories": [
|
||||||
|
"news"
|
||||||
|
],
|
||||||
|
"is_nsfw": false,
|
||||||
|
"logo": "https://i.imgur.com/2BXCg0x.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "MNetMovies2.za",
|
||||||
|
"name": "M-Net Movies 2",
|
||||||
|
"network": null,
|
||||||
|
"country": "ZA",
|
||||||
|
"subdivision": null,
|
||||||
|
"city": null,
|
||||||
|
"broadcast_area": [
|
||||||
|
"c/ZA"
|
||||||
|
],
|
||||||
|
"languages": [
|
||||||
|
"afr"
|
||||||
|
],
|
||||||
|
"categories": [],
|
||||||
|
"is_nsfw": false,
|
||||||
|
"logo": "https://rndcdn.dstv.com/dstvcms/2020/08/31/M-Net_Movies_2_Logo_4-3_lightbackground_xlrg.png"
|
||||||
|
}
|
||||||
|
]
|
1502
tests/__data__/input/data/countries.json
Normal file
1502
tests/__data__/input/data/countries.json
Normal file
File diff suppressed because it is too large
Load diff
352
tests/__data__/input/data/subdivisions.json
Normal file
352
tests/__data__/input/data/subdivisions.json
Normal file
|
@ -0,0 +1,352 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Alberta",
|
||||||
|
"code": "CA-AB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "British Columbia",
|
||||||
|
"code": "CA-BC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Manitoba",
|
||||||
|
"code": "CA-MB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "New Brunswick",
|
||||||
|
"code": "CA-NB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Newfoundland and Labrador",
|
||||||
|
"code": "CA-NL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Northwest Territories",
|
||||||
|
"code": "CA-NT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Nova Scotia",
|
||||||
|
"code": "CA-NS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Nunavut",
|
||||||
|
"code": "CA-NU"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Ontario",
|
||||||
|
"code": "CA-ON"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Prince Edward Island",
|
||||||
|
"code": "CA-PE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Quebec",
|
||||||
|
"code": "CA-QC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Saskatchewan",
|
||||||
|
"code": "CA-SK"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "CA",
|
||||||
|
"name": "Yukon",
|
||||||
|
"code": "CA-YT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Alabama",
|
||||||
|
"code": "US-AL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Alaska",
|
||||||
|
"code": "US-AK"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "American Samoa",
|
||||||
|
"code": "US-AS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Arizona",
|
||||||
|
"code": "US-AZ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Arkansas",
|
||||||
|
"code": "US-AR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "California",
|
||||||
|
"code": "US-CA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Colorado",
|
||||||
|
"code": "US-CO"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Connecticut",
|
||||||
|
"code": "US-CT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Delaware",
|
||||||
|
"code": "US-DE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "District of Columbia",
|
||||||
|
"code": "US-DC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Florida",
|
||||||
|
"code": "US-FL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Georgia",
|
||||||
|
"code": "US-GA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Guam",
|
||||||
|
"code": "US-GU"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Hawaii",
|
||||||
|
"code": "US-HI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Idaho",
|
||||||
|
"code": "US-ID"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Illinois",
|
||||||
|
"code": "US-IL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Indiana",
|
||||||
|
"code": "US-IN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Iowa",
|
||||||
|
"code": "US-IA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Kansas",
|
||||||
|
"code": "US-KS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Kentucky",
|
||||||
|
"code": "US-KY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Louisiana",
|
||||||
|
"code": "US-LA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Maine",
|
||||||
|
"code": "US-ME"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Maryland",
|
||||||
|
"code": "US-MD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Massachusetts",
|
||||||
|
"code": "US-MA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Michigan",
|
||||||
|
"code": "US-MI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Minnesota",
|
||||||
|
"code": "US-MN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Mississippi",
|
||||||
|
"code": "US-MS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Missouri",
|
||||||
|
"code": "US-MO"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Montana",
|
||||||
|
"code": "US-MT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Nebraska",
|
||||||
|
"code": "US-NE"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Nevada",
|
||||||
|
"code": "US-NV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "New Hampshire",
|
||||||
|
"code": "US-NH"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "New Jersey",
|
||||||
|
"code": "US-NJ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "New Mexico",
|
||||||
|
"code": "US-NM"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "New York",
|
||||||
|
"code": "US-NY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "North Carolina",
|
||||||
|
"code": "US-NC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "North Dakota",
|
||||||
|
"code": "US-ND"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Northern Mariana Islands",
|
||||||
|
"code": "US-MP"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Ohio",
|
||||||
|
"code": "US-OH"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Oklahoma",
|
||||||
|
"code": "US-OK"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Oregon",
|
||||||
|
"code": "US-OR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Pennsylvania",
|
||||||
|
"code": "US-PA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Puerto Rico",
|
||||||
|
"code": "US-PR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Rhode Island",
|
||||||
|
"code": "US-RI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "South Carolina",
|
||||||
|
"code": "US-SC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "South Dakota",
|
||||||
|
"code": "US-SD"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Tennessee",
|
||||||
|
"code": "US-TN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Texas",
|
||||||
|
"code": "US-TX"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "U.S. Virgin Islands",
|
||||||
|
"code": "US-VI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "United States Minor Outlying Islands",
|
||||||
|
"code": "US-UM"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Utah",
|
||||||
|
"code": "US-UT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Vermont",
|
||||||
|
"code": "US-VT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Virginia",
|
||||||
|
"code": "US-VA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Washington",
|
||||||
|
"code": "US-WA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "West Virginia",
|
||||||
|
"code": "US-WV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Wisconsin",
|
||||||
|
"code": "US-WI"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "US",
|
||||||
|
"name": "Wyoming",
|
||||||
|
"code": "US-WY"
|
||||||
|
}
|
||||||
|
]
|
|
@ -13,7 +13,7 @@ beforeEach(() => {
|
||||||
)
|
)
|
||||||
|
|
||||||
const stdout = execSync(
|
const stdout = execSync(
|
||||||
'DB_DIR=tests/__data__/temp/database PUBLIC_DIR=tests/__data__/output LOGS_DIR=tests/__data__/output/logs node scripts/commands/update-guides.js',
|
'DB_DIR=tests/__data__/temp/database DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output LOGS_DIR=tests/__data__/output/logs node scripts/commands/update-guides.js',
|
||||||
{ encoding: 'utf8' }
|
{ encoding: 'utf8' }
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,7 +7,7 @@ beforeEach(() => {
|
||||||
fs.mkdirSync('tests/__data__/output')
|
fs.mkdirSync('tests/__data__/output')
|
||||||
|
|
||||||
const stdout = 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 DATA_DIR=tests/__data__/input/data 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