-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
59 lines (49 loc) · 1.5 KB
/
handler.js
File metadata and controls
59 lines (49 loc) · 1.5 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// import Scraper from './src/scraper';
// import Slacker from './src/slack';
// import moment from 'moment';
// const moment = require("moment");
const scrapeIt = require("scrape-it");
var AWS = require("aws-sdk");
class Scraper {
async run() {
return scrapeIt("https://sellout.woot.com/plus/whack-a-deal", {
data: {
listItem: ".info",
title: {
selector: 'h2'
},
}
});
}
};
// var today = new Date();
// var dd = today.getDate();
module.exports.wootscrape = async (event, context) => {
try {
const controller = new Scraper();
// const today = moment().day()-1;
const res = await controller.run();
// console.log(today);
// console.log(res);
const response = res['data'];
if (JSON.stringify(response).includes(process.env.SEARCH_TERM)) {
// console.log(`Scraper Response is: ${JSON.stringify(response)}`);
console.log('Yep!');
var sns = new AWS.SNS();
var params = {
Message: "Go get that BoC!",
Subject: "BoC Exists!",
TopicArn: process.env.SNS_ARN
};
sns.publish(params, context.done);
} else {
console.log('Nope');
}
console.log('succeed');
return context.succeed({ statusCode: 200, body: response, headers: { 'Content-Type': 'application/json' } });
} catch (e) {
console.log('fail');
console.log(`Application ERROR: ${e.stack}`);
return context.fail({ statusCode: 500, body: `Application Error: ${e}`, headers });
}
};