-
Notifications
You must be signed in to change notification settings - Fork 0
/
bistroroyal.ts
36 lines (31 loc) · 1.21 KB
/
bistroroyal.ts
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
import { RestaurantMetaProps } from '@devolunch/shared';
import { Page } from 'puppeteer';
export const meta: RestaurantMetaProps = {
title: 'Bistro Royal',
url: 'https://bistroroyal.se/dagens-ratt/',
imageUrl: 'https://cdn42.gastrogate.com/files/29072/bistroroyal-bistro-1-1.jpg',
googleMapsUrl: 'https://goo.gl/maps/hSqYWPKgWVbSRj2s7',
coordinate: {
lat: 55.608996491841665,
lon: 12.999521057744403,
},
};
export const browserScrapeFunction = (page: Page) =>
page.evaluate(() => {
const todaySwedishFormat = new Date()
.toLocaleString('sv-SE', {
weekday: 'long',
})
.toLowerCase();
const lunchNode = [...document.querySelectorAll('.menu_header')]?.find((e) =>
e.textContent?.toLowerCase()?.includes(todaySwedishFormat),
);
const lunchMenuDiv = lunchNode?.parentNode?.parentNode as HTMLElement;
const htmlElement = lunchMenuDiv?.nextElementSibling as HTMLElement;
const raw = htmlElement ? [...htmlElement.querySelectorAll('.td_title')]?.map((e) => e.textContent?.trim()) : [];
const typeArray = ['meat' as const, 'meat' as const, 'fish' as const, 'veg' as const];
return raw.map((e, i) => ({
type: typeArray[i],
title: e,
}));
});