-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (50 loc) · 1.77 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
const request = require('request');
const http = require('http')
let counter = 0
process
.on('SIGTERM', shutdown('SIGTERM'))
.on('SIGINT', shutdown('SIGINT'))
.on('uncaughtException', shutdown('uncaughtException'));
function shutdown(signal) {
return (err) => {
console.log(`${ signal }...`);
if (err) console.error(err.stack || err);
setTimeout(() => {
console.log('...waited 5s, exiting.');
process.exit(err ? 1 : 0);
}, 5000).unref();
};
}
function vote(){
const options = {
method: 'POST',
url: 'https://voting-vote-producer.r7.com/vote',
headers: {
authority: 'voting-vote-producer.r7.com',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36',
'content-type': 'application/x-www-form-urlencoded',
accept: '*/*',
origin: 'https://afazenda.r7.com',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
referer: 'https://afazenda.r7.com/a-fazenda-12/votacao',
'accept-language': 'en-US,en;q=0.9,pt;q=0.8'
},
form: {voting_id: '271', alternative_id: '658'},
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(response.statusCode);
console.log(`votos: `, counter)
if (response.statusCode === 200) counter++
})
}
setInterval(vote, 5000)
const requestListener = function(req, res) {
res.writeHead(200);
res.end('Hello, World!');
}
const server = http.createServer(requestListener);
// this should be the last line
server.listen(parseInt(process.env.PORT) || 3000);