-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create dump of all standaardenregister's configurations
(https://github.com/Informatievlaanderen/OSLO-Standaarden/blob/configuratie/standaardenregister.json) into one xlsx
- Loading branch information
1 parent
d79ba46
commit ee3f85b
Showing
16 changed files
with
1,069 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const axios_1 = __importDefault(require("axios")); | ||
const configuration_1 = require("./types/configuration"); | ||
const utils_1 = require("./utils/utils"); | ||
const options = { | ||
method: 'GET', | ||
}; | ||
const getStandardRegistry = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const url = 'https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Standaarden/configuratie/standaardenregister.json'; | ||
try { | ||
const response = yield (0, axios_1.default)(url, options); | ||
const data = response === null || response === void 0 ? void 0 : response.data; | ||
return data || []; // Add a default return value in case of error or empty data | ||
} | ||
catch (error) { | ||
console.error('Error: unable to fetch the standards registry', error); | ||
return []; // Add a default return value in case of error or empty data | ||
} | ||
}); | ||
const getConfiguration = (url) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const response = yield (0, axios_1.default)(url, options); | ||
const data = response === null || response === void 0 ? void 0 : response.data; | ||
return data || {}; // Add a default return value in case of error or empty data | ||
} | ||
catch (error) { | ||
console.error('Error: unable to fetch the configuration', error); | ||
return configuration_1.defaultConfiguration; // Add a default return value in case of error or empty data | ||
} | ||
}); | ||
const resolveConfigurations = () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const standards = yield getStandardRegistry(); | ||
return standards.map((standard) => __awaiter(void 0, void 0, void 0, function* () { | ||
const rawUrl = (0, utils_1.generateRawGithubPath)(standard === null || standard === void 0 ? void 0 : standard.repository, 'standaardenregister', standard === null || standard === void 0 ? void 0 : standard.configuration); | ||
return getConfiguration(rawUrl); | ||
})); | ||
} | ||
catch (error) { | ||
console.error('Error: unable to resolve the configurations', error); | ||
return []; // Add a default return value in case of error or empty data | ||
} | ||
}); | ||
const saveConfigurations = () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const promises = yield resolveConfigurations(); | ||
const configurations = yield Promise.all(promises); | ||
const csvData = (0, utils_1.convertJsonToCsv)(configurations); | ||
(0, utils_1.writeFile)('report/merged_configurations.csv', csvData); | ||
(0, utils_1.convertCsvToExcel)(csvData, "report/merged_configurations"); | ||
} | ||
catch (error) { | ||
console.error('Error: unable to save the configuration in a file', error); | ||
} | ||
}); | ||
saveConfigurations(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import axios from 'axios' | ||
|
||
import { FetchOptions } from './types/fetchOptions' | ||
import { Configuration, defaultConfiguration } from './types/configuration' | ||
import { Standard } from './types/standard' | ||
import { generateRawGithubPath, writeFile, convertJsonToCsv, convertCsvToExcel } from './utils/utils' | ||
|
||
const options: FetchOptions = { | ||
method: 'GET', | ||
} | ||
|
||
const getStandardRegistry = async (): Promise<Array<Standard>> => { | ||
const url: string = 'https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Standaarden/configuratie/standaardenregister.json' | ||
|
||
try { | ||
const response = await axios<Array<Standard>>(url, options) | ||
const data = response?.data | ||
return data || [] // Add a default return value in case of error or empty data | ||
} catch (error: unknown) { | ||
console.error('Error: unable to fetch the standards registry', error) | ||
return [] // Add a default return value in case of error or empty data | ||
} | ||
} | ||
|
||
const getConfiguration = async (url: string): Promise<Configuration> => { | ||
try { | ||
const response = await axios<Configuration>(url, options) | ||
const data = response?.data | ||
return data || {} // Add a default return value in case of error or empty data | ||
} catch (error: unknown) { | ||
console.error('Error: unable to fetch the configuration', error) | ||
return defaultConfiguration // Add a default return value in case of error or empty data | ||
} | ||
} | ||
|
||
|
||
const resolveConfigurations = async (): Promise<Promise<Configuration>[]> => { | ||
try { | ||
const standards: Array<Standard> = await getStandardRegistry() | ||
return standards.map(async (standard: Standard) => { | ||
const rawUrl = generateRawGithubPath(standard?.repository, 'standaardenregister', standard?.configuration) | ||
return getConfiguration(rawUrl) | ||
}) | ||
} catch (error: unknown) { | ||
console.error('Error: unable to resolve the configurations', error) | ||
return [] // Add a default return value in case of error or empty data | ||
} | ||
} | ||
|
||
const saveConfigurations = async (): Promise<void> => { | ||
try { | ||
const promises = await resolveConfigurations() | ||
const configurations = await Promise.all(promises) | ||
const csvData = convertJsonToCsv(configurations) | ||
writeFile('report/merged_configurations.csv', csvData) | ||
convertCsvToExcel(csvData, "report/merged_configurations") | ||
} catch (error: unknown) { | ||
console.error('Error: unable to save the configuration in a file', error) | ||
} | ||
} | ||
|
||
saveConfigurations() |
Oops, something went wrong.