mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 20:51:25 +03:00
теперь можно отключить сбор фиата, удален мусор, удаления питоновской функции через регулярное выражение
This commit is contained in:
parent
615f3be62a
commit
b90a969a1c
1 changed files with 9 additions and 24 deletions
|
@ -2,40 +2,25 @@ const pool = require('../postgresql.js');
|
||||||
const yaml = require('yaml');
|
const yaml = require('yaml');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const axiosRetry = require('axios-retry').default
|
|
||||||
const config = yaml.parse(fs.readFileSync('./config.yaml', 'utf-8'));
|
const config = yaml.parse(fs.readFileSync('./config.yaml', 'utf-8'));
|
||||||
|
|
||||||
async function saveRate() {
|
async function save_fiat() {
|
||||||
config['currency'].forEach(
|
if (!config['currency']['collecting']['fiat']) return;
|
||||||
(value) => config['currency'].forEach(async (pair) => {
|
|
||||||
|
config['currency']['fiat'].forEach(
|
||||||
|
(value) => config['currency']['fiat'].forEach(async (pair) => {
|
||||||
if(value !== pair) {
|
if(value !== pair) {
|
||||||
const res = await axios.get(
|
const res = await axios.get(
|
||||||
`https://duckduckgo.com/js/spice/currency/1/${value}/${pair}`,
|
`https://duckduckgo.com/js/spice/currency/1/${value}/${pair}`,
|
||||||
{
|
{
|
||||||
timeout: 3000,
|
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']) {
|
const regExp = new RegExp('\\(\\s*(.*)\\s*\\);$', 'mg');
|
||||||
res.config.proxy = {
|
const data = JSON.parse(Array.from(res.data.matchAll(regExp))[0][1])
|
||||||
protocol: config['proxy']['protocol'],
|
console.log(data)
|
||||||
host: config['proxy']['host'],
|
|
||||||
port: config['proxy']['port'],
|
|
||||||
auth: {
|
|
||||||
username: config['proxy']['auth']['username'],
|
|
||||||
password: config['proxy']['auth']['password'],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
axiosRetry(axios, {
|
|
||||||
retries: 3
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = JSON.parse(res.data.replace('ddg_spice_currency(', '').replace(');', ''));
|
|
||||||
delete data['terms'];
|
delete data['terms'];
|
||||||
delete data['privacy'];
|
delete data['privacy'];
|
||||||
|
|
||||||
|
@ -65,4 +50,4 @@ async function saveRate() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = saveRate;
|
module.exports = save_fiat;
|
Loading…
Add table
Reference in a new issue