From b90a969a1ca6229f8dee18190f7e35149860652f Mon Sep 17 00:00:00 2001 From: Redume Date: Tue, 25 Jun 2024 01:10:49 +0300 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D1=81=D0=B1=D0=BE=D1=80=20=D1=84=D0=B8?= =?UTF-8?q?=D0=B0=D1=82=D0=B0,=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BC=D1=83=D1=81=D0=BE=D1=80,=20=D1=83=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=B8=D1=82=D0=BE=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=81=D0=BA=D0=BE=D0=B9=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D1=83=D0=BB=D1=8F=D1=80=D0=BD=D0=BE=D0=B5=20=D0=B2=D1=8B?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/{saveRate.js => save_fiat.js} | 33 ++++++++--------------------- 1 file changed, 9 insertions(+), 24 deletions(-) rename utils/{saveRate.js => save_fiat.js} (59%) diff --git a/utils/saveRate.js b/utils/save_fiat.js similarity index 59% rename from utils/saveRate.js rename to utils/save_fiat.js index 851782c..daf927f 100644 --- a/utils/saveRate.js +++ b/utils/save_fiat.js @@ -2,40 +2,25 @@ const pool = require('../postgresql.js'); const yaml = require('yaml'); const fs = require('fs'); const axios = require('axios'); -const axiosRetry = require('axios-retry').default const config = yaml.parse(fs.readFileSync('./config.yaml', 'utf-8')); -async function saveRate() { - config['currency'].forEach( - (value) => config['currency'].forEach(async (pair) => { +async function save_fiat() { + if (!config['currency']['collecting']['fiat']) return; + + config['currency']['fiat'].forEach( + (value) => config['currency']['fiat'].forEach(async (pair) => { if(value !== pair) { const res = await axios.get( `https://duckduckgo.com/js/spice/currency/1/${value}/${pair}`, { timeout: 3000, - headers: { - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' - } } ); - if (!config['proxy']['host'] && !res['data']) { - res.config.proxy = { - protocol: config['proxy']['protocol'], - host: config['proxy']['host'], - port: config['proxy']['port'], - auth: { - username: config['proxy']['auth']['username'], - password: config['proxy']['auth']['password'], - } - } - } + const regExp = new RegExp('\\(\\s*(.*)\\s*\\);$', 'mg'); + const data = JSON.parse(Array.from(res.data.matchAll(regExp))[0][1]) + console.log(data) - axiosRetry(axios, { - retries: 3 - }) - - const data = JSON.parse(res.data.replace('ddg_spice_currency(', '').replace(');', '')); delete data['terms']; delete data['privacy']; @@ -65,4 +50,4 @@ async function saveRate() { ); } -module.exports = saveRate; \ No newline at end of file +module.exports = save_fiat; \ No newline at end of file