-
Notifications
You must be signed in to change notification settings - Fork 0
/
chirashi.php
74 lines (56 loc) · 1.68 KB
/
chirashi.php
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
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/local/bin/php -q
<?php
include __DIR__.'/vendor/autoload.php';
use Joli\JoliNotif\Notification;
use Joli\JoliNotif\NotifierFactory;
const URL = 'https://www.frichti.co';
const API_URL = 'https://api-gateway.frichti.co/kitchens/2/menu';
const KEYWORDS = ['chirashi'];
function getMenu(): \stdClass
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data);
}
function sendNotification(string $dishes): void
{
$notifier = NotifierFactory::create();
$body = count($dishes) > 1
? $dishes.' sont disponibles sur Frichti.'
: $dishes.' est disponible sur Frichti.'
;
$notification =
(new Notification())
->setTitle('Votre plat est disponible sur Frichti !')
->setBody($body)
->setIcon(__DIR__.'/assets/yum.png')
->addOption('url', URL)
;
$notifier->send($notification);
}
function process(): void
{
$menu = getMenu();
$found = [];
foreach ($menu->menu as $cat) {
foreach ($cat->collects as $dish) {
foreach (KEYWORDS as $keyword) {
$keyword = strtolower($keyword);
if (isset($dish->products) && strpos(strtolower($dish->products->title), $keyword) !== false) {
$found[] = $dish->products->title;
}
}
}
}
$found = array_unique($found);
if (count($found) > 0) {
sendNotification(implode(', ', $found));
}
exit('Frichti checked on '.date('d/m/Y h:i:s a').'.');
}
process();
?>