This repository was archived by the owner on Jul 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (55 loc) · 2.26 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
const puppeteer = require('puppeteer');
// Read more about Pushover on https://pushover.net
var Push = require('pushover-notifications')
const http = require('http');
const CREDENTIALS = require('./credentials');
// These are all our CSS selcetors for the different elements of the page
// The easiest way is to inspect an element in Chrome (Option + CMD + j on a Mac), and right click on it
// in the HTML and Copy > Copy selector
const EMAIL_SELECTOR = '#login-form > div.login-body > div > div.control.email > input';
const PASSWORD_SELECTOR = '#login-form > div.login-body > div > div.control.password > input';
const BUTTON_SELECTOR = '#login-form > div.login-body > div > div.has-text-centered.signin > button';
const VIN_SECTION = '#page > div > div.pane-content-constrain > main > div > div > div > div > div:nth-child(2) > table > tbody > tr > td.model-name'
async function run() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
console.log(`Running check ${new Date()} -----`);
await page.goto('https://auth.tesla.com/login');
await page.click(EMAIL_SELECTOR);
console.log('Entering email...');
await page.keyboard.type(CREDENTIALS.username);
await page.click(PASSWORD_SELECTOR);
console.log('Entering password...');
await page.keyboard.type(CREDENTIALS.password);
console.log('Logging in!');
await page.click(BUTTON_SELECTOR);
await page.waitForNavigation();
console.log('Checking for VIN...');
await page.waitForSelector(VIN_SECTION);
const vinSection = await page.$(VIN_SECTION);
const html = await page.evaluate(body => body.innerHTML, vinSection);
await vinSection.dispose();
const regex = new RegExp(CREDENTIALS.reservationNumber, 'g');
// if it doesn't match it means that our reservation number on the page
// has been replaced with the VIN
if (!html.match(regex)) {
console.log('VIN found!!!');
var p = new Push({
user: CREDENTIALS.pushoverUser,
token: CREDENTIALS.pushoverKey
})
var msg = {
message: 'Tesla Model 3 has a VIN', // required
title: "boom!",
sound: 'magic',
priority: 1
}
p.send(msg, function (err, result) {
if (err) { throw err }
})
} else {
console.log('No VIN yet :/');
}
browser.close();
}
run();