Second commit

This commit is contained in:
Guillermo Bonet 2023-06-20 09:25:57 +02:00
parent 722ce87044
commit c7d1b1cd96
6 changed files with 75 additions and 24 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/node_modules
config.yml

View File

@ -19,3 +19,10 @@ Run this commands on project root directory to install Node dependencies.
```
$ npm install
```
Copy *config_template.yml*, put the name *config.yml* and configure it.
## Built With
* [Git](https://git-scm.com/)
* [Nodejs](https://nodejs.org/)

9
config_template.yml Normal file
View File

@ -0,0 +1,9 @@
axios:
method: GET
url: https://website.es/api/login
headers:
Authorization:
params:
data:
interval: 500
values:

36
main.js
View File

@ -1,22 +1,24 @@
const axios = require('axios');
import axios from 'axios';
import yml from 'js-yaml';
import fs from 'fs';
import chalk from 'chalk';
async function main() {
try {
const model = 'myModel';
const token = 'myToken';
const reqInterval = 500; // ms
const values = [
// Put here your values
];
for (let value of values) {
let url = `https://salix.verdnatura.es/api/${model}/${value}/download?access_token=${token}`;
await axios.get(url);
console.log(`Processed: ${value}`);
await new Promise(resolve => setTimeout(resolve, reqInterval));
const conf = yml.load(fs.readFileSync('./config.yml', 'utf8'));
for (let value of conf.values) {
await axios({
method: conf.axios.method,
url: conf.axios.url,
headers: conf.axios.headers,
data: conf.axios.data,
});
console.log(chalk.green('[Processed]', value));
await new Promise(resolve => setTimeout(resolve, conf.interval));
}
console.log(`It has been processed successfully!`);
console.log(chalk.green.bold('It has been processed successfully!'));
} catch (err) {
console.error('Error: ', err.response.data);
}
}
console.error(chalk.red('[Error]', err.message));
};
};
main();

33
package-lock.json generated
View File

@ -1,13 +1,20 @@
{
"name": "masive-request",
"name": "massive-request",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"axios": "^1.4.0"
"axios": "^1.4.0",
"chalk": "^5.2.0",
"js-yaml": "^4.1.0"
}
},
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@ -23,6 +30,17 @@
"proxy-from-env": "^1.1.0"
}
},
"node_modules/chalk": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz",
"integrity": "sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==",
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
@ -74,6 +92,17 @@
"node": ">= 6"
}
},
"node_modules/js-yaml": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
"dependencies": {
"argparse": "^2.0.1"
},
"bin": {
"js-yaml": "bin/js-yaml.js"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",

View File

@ -1,5 +1,8 @@
{
"dependencies": {
"axios": "^1.4.0"
}
"axios": "^1.4.0",
"chalk": "^5.2.0",
"js-yaml": "^4.1.0"
},
"type": "module"
}