-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathparser.js
More file actions
42 lines (36 loc) · 1.08 KB
/
Copy pathparser.js
File metadata and controls
42 lines (36 loc) · 1.08 KB
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
require('dotenv').config()
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
const nightmare = require('nightmare')()
const args = process.argv.slice(2)
const url = args[0]
const minPrice = args[1]
checkPrice()
async function checkPrice() {
try {
const priceString = await nightmare.goto(url)
.wait("#priceblock_ourprice")
.evaluate(() => document.getElementById("priceblock_ourprice").innerText)
.end()
const priceNumber = parseFloat(priceString.replace('$', ''))
if (priceNumber < minPrice) {
await sendEmail(
'Price Is Low',
`The price on ${url} has dropped below ${minPrice}`
)
}
} catch (e) {
await sendEmail('Amazon Price Checker Error', e.message)
throw e
}
}
function sendEmail(subject, body) {
const email = {
to: 'gisoteges@mail-desk.net',
from: 'amazon-price-checker@example.com',
subject: subject,
text: body,
html: body
}
return sgMail.send(email)
}