-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.js
62 lines (54 loc) · 1.47 KB
/
handler.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
'use strict';
module.exports.mealDeal = (event, context, callback) => {
try {
isMealDealAvailable();
} catch (err) {
console.log(err);
callback(err);
}
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
},
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
callback(null, response);
};
var request = require('request');
var cheerio = require('cheerio');
const isMealDealAvailable = () =>
request('http://www.marksandspencer.com/c/food-to-order/dine-in', function(
err,
resp,
html
) {
if (!err) {
const $ = cheerio.load(html);
const text = $('div[class=copy]')
.find('p[class=width80]')
.text();
const isAvailable =
text !==
'Sorry, our Dine In for two offer is not available this week. So why not make the most of our other in-store food offers and delicious Food to Order range?';
if (isAvailable) {
pingSlack('Yes it fucking is!!');
}
}
});
const pingSlack = message => {
request.post({
url:
'https://hooks.slack.com/services/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',
body: JSON.stringify({
text:
message +
' => <http://www.marksandspencer.com/c/food-to-order/dine-in>',
username: 'is the meal deal on??',
icon_emoji: ':monkey_face:',
}),
});
};