-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
131 lines (112 loc) · 3.32 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var request = require('request');
var cheerio = require('cheerio');
var nodemailer = require('nodemailer');
var fs = require('fs');
var http = require('http');
require('dotenv').config();
// Setting Timer for 5 minutes
let timer = 1000;
// Setting Initial Values of theatres that I already Know for locations (Since this is only for small purpose. Don't expect too much for me. Okay?)
let bangalore = 3;
let hyderabad = 3;
// Handle Bangalore Requests
function sendBangaloreMail() {
if (process.env.BANGALORE_RECIPIENTS) {
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD
}
});
const mailOptions = {
from: process.env.EMAIL,
to: process.env.BANGALORE_RECIPIENTS,
subject: 'Avengers is here.',
html:
'<p>Hey! This is a reminder that new theatre has started screening Avengers: End Game</p>'
};
return transporter.sendMail(mailOptions, (err, info) => {
if (err) {
console.log(err);
} else {
console.log(info);
}
});
} else {
return;
}
}
async function doBangaloreStuff() {
console.log('Doing Bangalore...');
clearInterval(timer);
setInterval(async () => {
console.log('Making the request');
await request(
'https://in.bookmyshow.com/buytickets/avengers-endgame-bengaluru/movie-bang-ET00100674-MT/20190426',
(error, response, html) => {
if (!error & (response.statusCode == 200)) {
var $ = cheerio.load(html);
if ($('#venuelist').children('.list').length > bangalore) {
bangalore++;
return sendBangaloreMail();
}
}
}
);
}, timer);
return true;
}
// Handle Hyderabad Requests
function sendHyderabadMail() {
if (process.env.HYDERABAD_RECIPIENTS) {
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD
}
});
const mailOptions = {
from: '[email protected]',
to: process.env.HYDERABAD_RECIPIENTS,
subject: 'Avengers is here.',
html:
'<p>Hey! This is a reminder that new theatre has started screening <a href="https://in.bookmyshow.com/buytickets/pvr-forum-sujana-mall-kukatpally-hyderabad/cinema-hyd-PVSF-MT/20190426">Avengers: End Game</a></p>'
};
return transporter.sendMail(mailOptions, (err, info) => {
if (err) {
console.log(err);
} else {
console.log(info);
}
});
} else {
return;
}
}
async function doHyderabadStuff() {
console.log('Doing Hyderabad...');
clearInterval(timer);
setInterval(async () => {
console.log('Making the request');
await request(
'https://in.bookmyshow.com/buytickets/pvr-forum-sujana-mall-kukatpally-hyderabad/cinema-hyd-PVSF-MT/20190426',
(error, response, html) => {
if (!error & (response.statusCode == 200)) {
var $ = cheerio.load(html);
if ($('#venuelist').children('.list').length > hyderabad) {
hyderabad++;
return sendHyderabadMail();
}
}
}
);
}, timer);
return true;
}
http.createServer().listen(3000, () => {
console.log('Server at PORT 3000 started.');
doBangaloreStuff();
doHyderabadStuff();
});