From fa91b18144912f4fb8d0023e69eef04411cdd0e1 Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Thu, 29 Feb 2024 20:26:35 +0530 Subject: [PATCH] refactor --- currscript.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/currscript.js b/currscript.js index a6832d5..8246682 100644 --- a/currscript.js +++ b/currscript.js @@ -44,6 +44,7 @@ for (const [key, value] of Object.entries(allcurr)) { allcurrLower[value.toLower const dateToday = new Date().toISOString().substring(0, 10) +const latestDir = path.join(__dirname, 'latest') begin() // Begins the program @@ -51,7 +52,7 @@ async function begin() { // launch the browser // await launchBrowser() - const latestDir = path.join(__dirname, 'latest') + const currJSON = await getCurrencies() // Get & Save All the available currencies in api @@ -180,12 +181,12 @@ function sortObjByKeys(obj) { // Generates the api files async function generateFiles(googBingCurrJSON) { - const currenciesDir = path.join(__dirname, 'latest', 'currencies') + const currenciesDir = path.join(latestDir, 'currencies') for (const [fromKey, fromValue] of Object.entries(googBingCurrJSON)) { const tempObj = {} tempObj['date'] = dateToday; tempObj[fromKey] = {} - const fromKeyDir = path.join(__dirname, 'latest', 'currencies', fromKey) + const fromKeyDir = path.join(latestDir, 'currencies', fromKey) fs.mkdirSync(fromKeyDir, { recursive: true })