-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
51 lines (45 loc) · 1.44 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const interval = 3000; // no less than 3000 ms
const count = 10000; // number of votes
const coinCode = 22253; // $MEWC code
const axios = require('axios');
const url = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/vote';
const getVotedId = async function () {
return await axios.get(url + '?id=' + coinCode)
.then((response) => {
return response.data['data']['unregisteredId'];
})
.catch(reason => {
// console.warn(reason['response']['data']);
});
};
const vote = async function (votedId) {
console.log('(do vote...)')
return await axios.post(url, JSON.stringify({
'cryptoId': coinCode,
'voted': 1, // 1: good, 2: bad
'votedId': votedId,
}), {
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => {
console.log(votedId, ':', response.data['status']['error_message']);
})
.catch(reason => {
console.warn(reason['response']['data']);
})
};
(async () => {
for (let i = 0; i < count; i++) {
console.log('==========')
const votedId = await getVotedId();
await new Promise(resolve => setTimeout(resolve, interval / 2));
if (votedId) {
await vote(votedId);
} else {
console.warn('(too freq...)')
}
await new Promise(resolve => setTimeout(resolve, interval / 2));
}
})();