-
Notifications
You must be signed in to change notification settings - Fork 3
/
lunch.js
32 lines (29 loc) · 912 Bytes
/
lunch.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
const puppeteer = require('puppeteer');
const lunch = async (ctx, restaurant) => {
const restaurantName = encodeURI(restaurant.trim());
let browser;
if (process.env.DEV) {
browser = await puppeteer.launch();
} else {
browser = await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser', // set according to dev machine
});
}
const page = await browser.newPage();
await page.setViewport({
width: 800,
height: 1000,
});
await page.goto(`https://www.lounaat.info/haku?etsi=${restaurantName}`);
const [error] = await page.$x('//*[contains(text(), "Emme löytäneet yhtään ravintolaa")]');
if (error) {
ctx.reply('Ei löytynyt yhtään ravintolaa, koitas uudelleen.');
} else {
await page.screenshot({
path: 'lunch.png',
});
await browser.close();
ctx.replyWithPhoto({ source: './lunch.png' });
}
};
module.exports = lunch;