-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCinemaSafe.js
604 lines (478 loc) · 18.6 KB
/
CinemaSafe.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
const puppeteer = require('puppeteer-extra')
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
const AdblockerPlugin = require('puppeteer-extra-plugin-adblocker')
var http = require('http');
const https = require('https');
var fs = require('fs');
const { moveCursor } = require('readline');
const axios = require('axios');
const Jimp = require("jimp");
colors = require('colors');
const clear = require('clear');
const figlet = require('figlet');
//Initialize plugins
require('console-png').attachTo(console);
colors.enable()
puppeteer.use(StealthPlugin());
puppeteer.use(AdblockerPlugin({ blockTrackers: true }));
const prompt = require("prompt-sync")({ sigint: true });
// Vanity screen
console.clear();
console.log('==================================================================================='.cyan);
console.log(' ██████╗██╗███╗ ██╗███████╗███╗ ███╗ █████╗ ███████╗ █████╗ ███████╗███████╗'.magenta);
console.log('██╔════╝██║████╗ ██║██╔════╝████╗ ████║██╔══██╗██╔════╝██╔══██╗██╔════╝██╔════╝'.magenta);
console.log('██║ ██║██╔██╗ ██║█████╗ ██╔████╔██║███████║███████╗███████║█████╗ █████╗ '.magenta);
console.log('██║ ██║██║╚██╗██║██╔══╝ ██║╚██╔╝██║██╔══██║╚════██║██╔══██║██╔══╝ ██╔══╝ '.magenta);
console.log('╚██████╗██║██║ ╚████║███████╗██║ ╚═╝ ██║██║ ██║███████║██║ ██║██║ ███████╗'.magenta);
console.log(' ╚═════╝╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚══════╝'.magenta);
console.log('===================================================================================='.cyan);
// console.log(
// figlet.textSync('CINEMA-SAFE', { horizontalLayout: 'full' }).cyan
// );
const movieInfo = async (url) => {
console.log('');
console.log('==================================================================================='.cyan);
console.log('***** + + + Commencing Target Acquisition + + + + *****'.cyan.bgMagenta);
console.log('==================================================================================='.cyan);
console.log('');
//Web Initialization
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.setCacheEnabled(false);
page.setViewport({ width: 1280, height: 926 });
try {
var response = await page.goto(url, {
waitUntil: "networkidle0",
timeout: 60000
});
} catch (error) {
console.log("Status code:", response.status());
console.log(error.message);
}
const getTitle = await page.waitForSelector('#ShowtimeTitleLink');
const title = await page.evaluate(name => name.innerText, getTitle);
console.log('Title: ' + title.cyan);
const getShowTime = await page.waitForSelector('#HeaderTitleWrapper > div > div > div > p.showtime-info__date.dark__section');
const time = await page.evaluate(name => name.innerText, getShowTime);
if (!!time) {
var todaysDate = new Date()
var currentYear = todaysDate.getFullYear()
let atRemove = time.replace("at", "");
var dateTime = atRemove.split(",")
var date = dateTime[1].trim() + currentYear;
showTime = new Date(date);
}
console.log('Showime: ' + time.cyan);
const getTheatre = await page.waitForSelector('#HeaderTitleWrapper > div > div > div > p.showtime-info__theater.dark__section');
const theatre = await page.evaluate(name => name.innerText, getTheatre);
console.log('Theatre: ' + theatre.cyan);
// const getAddress = await page.waitForSelector('#ShowtimeTitleLink');
// const address = await page.evaluate(name => name.innerText, getAddress);
// console.log('Address: ' + address);
const getPoster = await page.waitForSelector('#HeaderTitleWrapper > div > div > a > img');
const imgSRC = await getPoster.getProperty('src');
const imageURL = await imgSRC.jsonValue();
async function gatherImage(url){
await Jimp.read(url)
.then((image) => {
return image
.resize(54, 80)
.quality(100)
.write("moviePoster.png")
})
.catch((err) => {
console.warn("ERRRRROR")
console.log(err)
});
}
async function displayImage(url){
//await downloadImage(imageURL, 'moviePoster.jpg');
await gatherImage(url);
var image = require('fs').readFileSync(__dirname + '/moviePoster.png');
console.png(image);
}
try{
displayImage(imageURL)
}
catch{console.log("Unable to display image")}
//Clean up browser
await browser.close();
//await new Promise(resolve => setTimeout(resolve, 5000));
}
async function checkSeat(url, seatToCheck) {
console.log("Checking ".cyan + seatToCheck.cyan);
var status = "Error"
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.setCacheEnabled(false);
page.setViewport({ width: 1280, height: 926 });
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36');
try {
var response = await page.goto(url, {
waitUntil: "load",
timeout: 60000
});
} catch (error) {
console.warn("Error")
console.warn("Status code:", response.status());
console.log(error.message);
}
try {
const seat = await page.waitForSelector("#" + seatToCheck);
const seatAvailiability = await seat.evaluate(node => node.outerHTML, seat);
if (seatAvailiability.includes("This seat is available")) {
status = "Open"
}
else if (seatAvailiability.includes("unavailable")) {
status = "Unavailable"
}
await browser.close();
return status
} catch (error) {
console.warn("Error in checkSeat function")
console.log(error.message);
await browser.close();
}
}
const ReserveBufferSeats = async (firstBufferSeat, secondBufferSeat, url) => {
console.log('');
console.log("Reserving seats".cyan)
//Initialize browser for reserving seats
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.setCacheEnabled(false);
page.setViewport({ width: 1280, height: 926 });
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36');
try {
const response = await page.goto(url, {
waitUntil: "networkidle0",
timeout: 60000
});
} catch (error) {
console.warn("Error")
console.warn("Status code:", response.status());
console.log(error.message);
}
//Buffer Seat 1
try {
const bufferSeat1 = await page.waitForSelector("#" + firstBufferSeat);
if (bufferSeat1) {
await bufferSeat1.click();
console.log("✔️ Buffer Seat 1 CLICKED: Success!");
}
else {
console.log("❌ ❌ ❌ ERROR on Buffer Seat 1 SELECT ❌ ❌ ❌");
}
await sleep(1000)
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
} catch (error) {
console.log("❌ ❌ ❌ ERROR on Bufffer seat 1 TRY ❌ ❌ ❌");
console.log(error.message);
}
//Buffer Seat 2
try {
const bufferSeat2 = await page.waitForSelector("#" + secondBufferSeat);
if (bufferSeat2) {
await bufferSeat2.click();
console.log("✔️ Buffer Seat 2 CLICKED: Success!");
}
else {
console.log("❌ ❌ ❌ ERROR on Buffer Seat 2 SELECT ❌ ❌ ❌");
}
await sleep(1000)
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
} catch (error) {
console.log("❌ ❌ ❌ ERROR on Buffer seat 2 TRY ❌ ❌ ❌");
console.log(error.message);
}
//Check for 2 buffer seats selected
try {
const checkSeats = await page.waitForSelector("#stickyFooterSelectedCount");
const seatValidatiion = await page.evaluate(name => name.innerText, checkSeats);
console.log(seatValidatiion.replace());
if (seatValidatiion === '0 Selected:') {
console.log(' ⌛ Seats still reserved - looping to maintain... ⌛');
await browser.close();
console.log('====================================================================================');
console.log('====================================================================================');
}
else {
//Buffer seat clicks to complete - Press NEXT button to lock in
const bufferSeatFirstNext = await page.waitForSelector("#NextButton");
if (bufferSeatFirstNext) {
await bufferSeatFirstNext.click();
const bufferSeatSecondNext = await page.waitForSelector("#ticket-selection-overlay-next-btn");
if (bufferSeatSecondNext) {
await bufferSeatSecondNext.click();
console.log(" ✅ Buffer Seat selection COMPLETE! ✅");
}
else {
console.log("❌ ❌ ❌ ERROR on Buffer Seat Second Next ❌ ❌ ❌");
}
}
else {
console.log("❌ ❌ ❌ ERROR on Buffer First Next ❌ ❌ ❌");
}
console.log("");
await page.waitForSelector('#buynow-continue-btn', {
visible: true,
});
const popupNextButton = await page.waitForSelector('#buynow-continue-btn', {visible: true})
if(popupNextButton){
await popupNextButton.click()
}
else {
console.log("❌ ❌ ❌ ERROR on Popup Next ❌ ❌ ❌");
}
const priceLOL = await page.waitForSelector("#purchaseTotal");
const dollarsSaved = await page.evaluate(price => price.innerText, priceLOL);
console.log("Price: " + dollarsSaved)
// await page.screenshot({
// path: "screenshots/screenshot.png",
// fullPage: true
// });
await browser.close();
}
} catch (error) {
console.log("❌ ❌ ❌ ERROR on final step TRY ❌ ❌ ❌");
console.log(error.message);
await browser.close();
}
}
const targetSeats = async (seats, url) => {
console.log('');
console.log("Reserving seats".cyan)
//Initialize browser for reserving seats
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.setCacheEnabled(false);
page.setViewport({ width: 1280, height: 926 });
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36');
try {
const response = await page.goto(url, {
waitUntil: "networkidle0",
timeout: 60000
});
} catch (error) {
console.warn("Error")
console.warn("Status code:", response.status());
console.log(error.message);
}
for (const seat of seats){
try {
const targetSeat = await page.waitForSelector("#" + seat);
if (targetSeat) {
await targetSeat.click();
console.log(`✔️ ${seat} CLICKED: Success!`);
}
else {
console.log(`❌ ❌ ❌ ERROR selecting seat ${seat} ❌ ❌ ❌`);
}
await sleep(1000)
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
} catch (error) {
console.log(`❌ ❌ ❌ ERROR on seat ${seat} TRY ❌ ❌ ❌`);
console.log(error.message);
}
}
//Check for 2 buffer seats selected
try {
const checkSeats = await page.waitForSelector("#stickyFooterSelectedCount");
const seatValidatiion = await page.evaluate(name => name.innerText, checkSeats);
console.log(seatValidatiion.replace());
if (seatValidatiion === '0 Selected:') {
console.log(' ⌛ Seats still reserved - looping to maintain... ⌛');
await browser.close();
console.log('====================================================================================');
console.log('====================================================================================');
}
else {
//Buffer seat clicks to complete - Press NEXT button to lock in
const bufferSeatFirstNext = await page.waitForSelector("#NextButton");
if (bufferSeatFirstNext) {
await bufferSeatFirstNext.click();
const bufferSeatSecondNext = await page.waitForSelector("#ticket-selection-overlay-next-btn");
if (bufferSeatSecondNext) {
await bufferSeatSecondNext.click();
console.log(" ✅ Seat Targetting selection COMPLETE! ✅");
}
else {
console.log("❌ ❌ ❌ ERROR on Seat Targetting Second Next ❌ ❌ ❌");
}
}
else {
console.log("❌ ❌ ❌ ERROR on Seat Targetting First Next ❌ ❌ ❌");
}
console.log("");
await page.waitForSelector('#buynow-continue-btn', {
visible: true,
});
const popupNextButton = await page.waitForSelector('#buynow-continue-btn', {visible: true})
if(popupNextButton){
await popupNextButton.click()
}
else {
console.log("❌ ❌ ❌ ERROR on Popup Next ❌ ❌ ❌");
}
const priceLOL = await page.waitForSelector("#purchaseTotal");
const dollarsSaved = await page.evaluate(price => price.innerText, priceLOL);
console.log("Price: " + dollarsSaved)
// await page.screenshot({
// path: "screenshots/screenshot.png",
// fullPage: true
// });
await browser.close();
}
} catch (error) {
console.log("❌ ❌ ❌ ERROR on final Seat Targetting TRY ❌ ❌ ❌");
console.log(error.message);
await browser.close();
}
}
const bufferLoop = async (startSeat, endSeat, url) => {
var todaysDate = new Date()
await movieInfo(url);
if (!!showTime) {
if (todaysDate.getTime() < showTime.getTime())
console.log("Show has not happened yet: Initiating loop".magenta);
else
console.log("Show has happened at " + todaysDate);
}
//Seat Logic (determine how many seats and what buffer seats are)
const startSeatNumber = startSeat.replace(/\D/g, '');
const endSeatNumber = endSeat.replace(/\D/g, '');
let amountToBuffer = (endSeatNumber - startSeatNumber) + 1;
startSeat = startSeat.toUpperCase();
var row = startSeat.replace(/[^a-zA-Z]+/g, '');
var firstBufferSeat = row + (+startSeatNumber - 1)
var secondBufferSeat = row + (+endSeatNumber + 1)
//Loops every 30 seconds until showtime passes
while (todaysDate.getTime() < showTime.getTime()) {
var loopTime = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')
console.log('');
console.log("Loop began at: ".cyan + loopTime)
//Check that seats are availiable
var seatCheck1 = await checkSeat(url, firstBufferSeat)
var seatCheck2 = await checkSeat(url, secondBufferSeat)
if (seatCheck1.includes("Open") && seatCheck2.includes("Open")) {
await ReserveBufferSeats(firstBufferSeat, secondBufferSeat, url)
console.log("Aquired both seats, Looping to maintain reservation".magenta)
}
else if (seatCheck1.includes("Unavailable") || seatCheck2.includes("Unavailable")) { //
console.log(firstBufferSeat.magenta + ": ".magenta + seatCheck1.magenta + " - ".magenta + secondBufferSeat.magenta + ": ".magenta + seatCheck2.magenta )
console.log("Looping to aquire seats... Unsuccessful".red)
}
else {
console.log("Error checking for seat availiability".red)
console.log("Looping from an ERROR STATE to check seat availiability".red)
}
console.log('');
console.log('-------------------------------------------------'.zebra);
await new Promise(resolve => setTimeout(resolve, 45000));
}
console.time("dbsave");
console.log("Showtime occured at ")
console.timeEnd("dbsave");
console.log("Showtime occured at " + showtime)
}
const targetLoop = async (seats, url) => {
var todaysDate = new Date()
await movieInfo(url);
if (!!showTime) {
if (todaysDate.getTime() < showTime.getTime())
console.log("Show has not happened yet: Initiating loop".magenta);
else
console.log("Show has happened at " + todaysDate);
}
//Loops every 30 seconds until showtime passes
while (todaysDate.getTime() < showTime.getTime()) {
var loopTime = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')
console.log('');
console.log("Loop began at: ".cyan + loopTime)
//Check that seats are availiable
var seatCheck = await checkSeat(url, seats[0])
if (seatCheck.includes("Open") ) {
await targetSeats(seats, url)
console.log("Aquired both seats, Looping to maintain reservation".magenta)
}
else if (seatCheck.includes("Unavailable") ) { //
console.log(seats[0].magenta + ": ".magenta + seatCheck.magenta)
console.log("Looping to acquire seats... Unsuccessful".red)
}
else {
console.log("Error checking for seat availiability".red)
console.log("Looping from an ERROR STATE to check seat availiability".red)
}
console.log('');
console.log('-------------------------------------------------'.zebra);
await new Promise(resolve => setTimeout(resolve, 45000));
}
console.time("dbsave");
console.log("Showtime occured at ")
console.timeEnd("dbsave");
console.log("Showtime occured at " + showtime)
}
//const menuSelection = prompt("CinemaSafe.js ");
var showTime
const prompts = require('prompts');
(async () => {
const response = await prompts({
type: 'select',
name: 'value',
message: 'Mode select:',
choices: [
{ title: 'Buffer Mode', description: 'Create buffer zone around a group of seats', value: 'Buffer' },
//{ title: 'Green', value: '#00ff00', disabled: true },
{ title: 'Target Mode', description: 'Target a list up to 20 seats, may be non-sequential', value: 'Target' }
],
initial: 1
});
console.log('');
if (response.value.includes("Buffer")) {
const link = await prompts({
type: 'text',
name: 'value',
message: `Fandango Link: (link from seat selection page)`,
validate: value => !value.includes("https://tickets.fandango.com/") ? `Link should start with: https://tickets.fandango.com/` : true
});
console.log('');
const startSeat = prompt("START seat: ");
const endSeat = prompt("END seat: ");
console.log('');
bufferLoop(startSeat, endSeat, link.value);
} console.log('');
if (response.value.includes("Target")) {
//const link = prompt("Fandango Link: ");
const link = await prompts({
type: 'text',
name: 'value',
message: `Fandango Link: (link from seat selection page)`.cyan,
validate: value => !value.includes("https://tickets.fandango.com/") ? `Link should start with: https://tickets.fandango.com/` : true
});
console.log('');
const seats = await prompts({
type: 'list',
name: 'targets',
message: 'Enter up to 20 targets (comma seperated): ',
initial: '',
separator: ','
});
console.log('');
const uppercaseSeats= seats.targets.map(targets => targets.toUpperCase());
targetLoop(uppercaseSeats, link.value);
}
})();
//ReserveBufferSeats(startSeat, endSeat, link);
// a1,b4,c5,d6,e7,a5,b6,d4,e3