-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
109 lines (99 loc) · 3.48 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
import puppeteer from "puppeteer-extra";
import StealthPlugin from "puppeteer-extra-plugin-stealth";
import SmartProxy from "zyte-smartproxy-puppeteer";
import { default as twilio } from 'twilio'
const accountSid = '<INSERT TWILIO ACCOUNT SID>';
const authToken = '<INSERT TWILIO AUTH TOKEN>';
const client = twilio(accountSid, authToken);
puppeteer.use(StealthPlugin())
puppeteer.use(SmartProxy) // optional but need a paid account
const getAlerts = async () => {
const browser = await puppeteer.launch({
headless: false,
args: [
// if you want to work with proxies
// '--incognito',
// '--proxy-server=127.0.0.1:9876'
]
});
const event = process.argv[2].split("/");
let page = await browser.newPage();
// await page.setJavaScriptEnabled(false)
let pages = await browser.pages();
const oldPage = pages[0];
await oldPage.close();
await page.goto(process.argv[2], {
waitUntil: "domcontentloaded",
timeout: 0
});
await page.waitForNetworkIdle();
let html = await page.content();
console.log(html)
sleep(1000)
while (html.includes("Your browser hit a snag")){
sleep(5000)
await page.reload();
html = await page.content();
console.log(html)
}
if (!html.includes("edp-quantity-filter-button")) {
console.log("No Tickets Available");
while(!html.includes("edp-quantity-filter-button")){
const msToRun = 15000 // 10 seconds
const t0 = performance.now() // or Date.now()
let flag = false;
while (!flag) {
html = await page.content();
if (html.includes("edp-quantity-filter-button")){
await client.messages
.create({
body: 'ALERT: Resale for ' + event.at(3) + ' available here: ' + process.argv[2],
from: '<INSERT TWILIO PHONE NUMBER>',
to: '<INSERT DESINATION PHONE NUMBERS>'
})
console.log('SMS sent successfully! 🌟');
await browser.close();
return true;
}
if (performance.now() - t0 >= msToRun) {
flag = true;
}
}
await page.reload();
html = await page.content();
while (html.includes("Your browser hit a snag")){
sleep(5000)
await page.reload();
html = await page.content();
console.log(html)
}
console.log(html)
console.log("No Tickets Available");
console.log('page is now refreshing...')
}
}
if (html.includes("edp-quantity-filter-button")){
await client.messages
.create({
body: 'ALERT: Resale for ' + event.at(3) + ' available here: ' + process.argv[2],
from: '<INSERT TWILIO PHONE NUMBER>',
to: '<INSERT DESINATION PHONE NUMBERS>'
})
console.log('SMS sent successfully! 🌟');
await browser.close();
return true;
}
};
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
// Start the scraping
getAlerts().then(r => {
if (r) {
console.log('sending alerts')
}
});