Skip to content

Commit

Permalink
1 api task
Browse files Browse the repository at this point in the history
  • Loading branch information
redji committed Mar 20, 2024
1 parent 263bb89 commit 6b5d90a
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm i
provide your API_Key in prompt.js
node prompt.js
100 changes: 100 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "aiprompty",
"version": "1.0.0",
"description": "",
"main": "prompt.js",
"type":"module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Michał Furmaniak",
"license": "ISC",
"dependencies": {
"node-fetch": "^3.3.2"
}
}
54 changes: 54 additions & 0 deletions prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import fetch from 'node-fetch';

const APIKey = '';

// Function to make a request with a delay
async function makeRequestWithDelay(url, options, delay) {
return new Promise((resolve, reject) => {
setTimeout(async () => {
try {
const response = await fetch(url, options);
const data = await response.json();
resolve(data);
} catch (error) {
reject(error);
}
}, delay);
});
}

// First curl command
fetch('https://tasks.aidevs.pl/token/helloapi', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({apikey: APIKey})
})
.then(async (response) => {
const data = await response.json();
console.log(data);
const token = data.token;
const url = `https://tasks.aidevs.pl/task/${token}`;
console.log(token);
console.log(url);

// Second curl command with a delay of 2000 milliseconds (2 seconds)
const response2 = await makeRequestWithDelay(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}, 10);
const cookie = response2.cookie;
// Third curl command with a delay of 2000 milliseconds (2 seconds)
const response3 = await makeRequestWithDelay(`https://tasks.aidevs.pl/answer/${token}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({answer: cookie})
}, 10);
console.log(response3);
})
.catch(error => console.error('Error:', error));

0 comments on commit 6b5d90a

Please sign in to comment.