mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 04:33:11 +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 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;
|
||||
module.exports = save_fiat;
|
Loading…
Add table
Reference in a new issue