mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 20:51:25 +03:00
добавлен юзер агент и при ошибке по идеи должно повторятся запрос
This commit is contained in:
parent
4a6a2b2a77
commit
dab54b54f5
2 changed files with 14 additions and 5 deletions
|
@ -8,6 +8,7 @@
|
||||||
"license": "LGPL-3.0-only",
|
"license": "LGPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.7",
|
"axios": "^1.6.7",
|
||||||
|
"axios-retry": "^4.0.0",
|
||||||
"fastify": "^4.26.1",
|
"fastify": "^4.26.1",
|
||||||
"node-schedule": "^2.1.1",
|
"node-schedule": "^2.1.1",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.11.3",
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
const pool = require("../postgresql.js");
|
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 config = yaml.parse(fs.readFileSync("./config.yaml", "utf-8"));
|
const axiosRetry = require('axios-retry').default
|
||||||
|
const config = yaml.parse(fs.readFileSync('./config.yaml', 'utf-8'));
|
||||||
|
|
||||||
async function saveRate() {
|
async function saveRate() {
|
||||||
config['currency'].forEach(
|
config['currency'].forEach(
|
||||||
|
@ -12,6 +13,9 @@ async function saveRate() {
|
||||||
`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'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -27,6 +31,10 @@ async function saveRate() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
axiosRetry(axios, {
|
||||||
|
retries: 3
|
||||||
|
})
|
||||||
|
|
||||||
const data = JSON.parse(res.data.replace('ddg_spice_currency(', '').replace(');', ''));
|
const data = JSON.parse(res.data.replace('ddg_spice_currency(', '').replace(');', ''));
|
||||||
delete data['terms'];
|
delete data['terms'];
|
||||||
delete data['privacy'];
|
delete data['privacy'];
|
||||||
|
|
Loading…
Add table
Reference in a new issue