-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
91 lines (63 loc) · 2.04 KB
/
app.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const co = require('co');
const request = require('co-request');
const cheerio = require('cheerio');
const _ = require('lodash');
const exec = require('child_process').exec;
const fs = require('fs');
const CHECK_INTERVAL_MS = 50000;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let cookieJar = request.jar();
let buildRequest =async function (uri, method) {
console.log("start")
console.log(uri)
await sleep(5000);
console.log("finish")
return request({
uri: uri,
method: method,
jar: cookieJar,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36',
}
});
};
let loadurl_events = function () {
let listofurls=[]
const allFileContents = fs.readFileSync('event_urls.txt', 'utf-8');
allFileContents.split(/\r?\n/).forEach(line => {
listofurls.push(line);
});
console.log(listofurls);
return listofurls;
};
let tickets_already_notified=[];
let availableTicket= function (url) {
tickets_already_notified.push(url);
exec('I=6; while [ $I -gt 0 ]; do spd-say "I found a ticket for you"; sleep 3; I=$((I - 1)); done') //PLAYING SOUND FOR 6 TIMES, FIRST SIMPLE NOTIFICATION SYSTEM
exec(`python automaticClick.py ${url}`); //OPENING THE PYTHON SCRIPT TO RUN SELENIUM
process.exit(0);
}
let app = function () {
let events=loadurl_events();
return co(function* () {
console.log()
for (var EVENT_URL of events){
let result = yield buildRequest(EVENT_URL, 'GET');
let $ = cheerio.load(result.body);
let datalisting=$('a[data-testid=listing]');
if(datalisting != null){
datalisting.children().each((index,data) => {
let urlticket=data['parent'].attribs['href']
console.log("Calling the URL for the ticket")
availableTicket(urlticket,"TEST");
});
}
}
}).catch(ex => {
console.log(ex);
});
};
app();
setInterval(app, CHECK_INTERVAL_MS);