From 8780c1f77237ac9aa1b5cb7227095bfae66f6b88 Mon Sep 17 00:00:00 2001 From: Redume Date: Thu, 1 Aug 2024 00:43:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B5=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- collect-currency/save_fiat.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/collect-currency/save_fiat.js b/collect-currency/save_fiat.js index 1f6b0d6..bf27595 100644 --- a/collect-currency/save_fiat.js +++ b/collect-currency/save_fiat.js @@ -12,12 +12,10 @@ async function save_fiat() { `https://duckduckgo.com/js/spice/currency/1/${value}/${pair}`, { timeout: 3000, - } - ); + }); const regExp = new RegExp('\\(\\s*(.*)\\s*\\);$', 'mg'); - const data = JSON.parse(Array.from(res.data.matchAll(regExp))[0][1]) - console.log(data) + const data = JSON.parse(Array.from(res.data.matchAll(regExp))[0][1]); delete data['terms']; delete data['privacy']; @@ -29,23 +27,22 @@ async function save_fiat() { value, pair, new Date(data['timestamp']).toLocaleDateString() - ], - ).then(async (db) => { - if (!db['rows'][0]) { - await pool.query(`INSERT INTO currency (from_currency, conv_currency, rate, date) - VALUES ($1, $2, $3, $4) RETURNING *`, - [ - value, - pair, - data['to'][0]['mid'].toString().slice(0, point), - new Date(data['timestamp']).toLocaleDateString() - ], - ); - } + ]).then(async (db) => { + if (db['rows'][0]) return; + + await pool.query(`INSERT INTO currency (from_currency, conv_currency, rate, date) + VALUES ($1, $2, $3, $4) RETURNING *`, + [ + value, + pair, + data['to'][0]['mid'].toString().slice(0, point), + new Date(data['timestamp']).toLocaleDateString() + ], + ); }); } }) ); } -module.exports = save_fiat; +module.exports = save_fiat; \ No newline at end of file