-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (35 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import logger from "../utils/logger.js";
import { PROVIDERS_DATA_FOLDER } from "./constants.js";
import { buildAllDataList } from "./dataUnifiers/allDataList.js";
import { buildSlimList } from "./dataUnifiers/slimCountryList.js";
import { fetchAllProvidersData } from "./providers/index.js";
import { readFilesInAFolder } from "./utils/readFilesInAFolder.js";
async function gatherAllCountriesData() {
logger.info(`UPDATE COUNTRY CPI DATA - started`);
await fetchAllProvidersData();
logger.info(`> Read Providers Data - started`);
const sortedAndParsedProviderFiles = await readFilesInAFolder(
PROVIDERS_DATA_FOLDER
)
.then(
(files) =>
files
.map(({ contents }) => JSON.parse(contents))
.sort(
(providerA, providerB) =>
(providerA.meta.preference || 999) -
(providerB.meta.preference || 999)
)
// descending order of priority (lower number = higher priority)
)
.catch((error) => {
logger.error(error);
});
logger.info(`> Read Providers Data - finished`);
const allGatheredData = await buildAllDataList(sortedAndParsedProviderFiles);
const countryList = await buildSlimList(allGatheredData);
logger.info(
`UPDATE COUNTRY CPI DATA - finished with ${countryList.length} records`
);
}
gatherAllCountriesData();