-
Notifications
You must be signed in to change notification settings - Fork 1
/
theatre.js
63 lines (58 loc) · 1.47 KB
/
theatre.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
const rp = require('request-promise');
const cheerio = require('cheerio');
const open = require('opn')
const options = {
uri : `https://in.bookmyshow.com/buytickets/pvr-forum-mall-koramangala/cinema-bang-PVBN-MT/20190410`, //URL of the Theatre in BookMyShow
transform: function (body) {
return cheerio.load(body);
}
}
const checkStatus = (keywords) => {
try{
return new Promise((resolve,reject) => {
console.log("Checking...")
rp(options).
then(function(data){
let raw = data.html()
keywords.forEach((word) => {
if(raw.toLowerCase().indexOf(word) >=0){
resolve(true)
}
})
resolve(false)
}).catch(function(error){
console.log(error)
Promise.reject('Error')
})
})
}
catch(err){
throw err
}
}
const sleep = async (ms) =>{
return new Promise( (resolve,reject) => {
setTimeout(()=>{ resolve()}, ms)
})
}
const main = async () =>{
try{
while(1){
if(await checkStatus(['endgame'])){ //Enter the name of the movie
console.log("Booking open. Opening browser")
open(options.uri)
await sleep(250)
break
}
else{
console.log("Not found. Waiting 10 seconds.")
await sleep(10000)
}
}
process.exit(1)
}
catch(err){
console.log("Error")
}
}
main()