-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcron.php
62 lines (53 loc) · 1.65 KB
/
cron.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
<?php
use Models\Offer;
use Utils\BrowserFactory;
use Utils\Log;
use Utils\ProviderHelper;
use Utils\Utils;
require 'boot.php';
//get urls
$urls = explode('|', env('URLS'));
if (!count($urls)) {
Log::critical('stopped execution since no urls have been found!');
exit;
}
// register providers
ProviderHelper::initialize();
if (!ProviderHelper::count()) {
Log::critical('stopped execution since no providers have been found!');
exit;
}
// get browser
$browser = BrowserFactory::getBrowser();
foreach ($urls as $url) {
Log::info('new url', ['url' => $url]);
$provider = ProviderHelper::getInstanceFor($url, $browser);
if (!$provider) {
Log::critical('skipped url since no matching provider has been found!');
continue;
}
$offers = $provider->parseOffers($url);
foreach ($offers as $offer) {
// skip existing offers
if (Offer::where('provider', $offer->provider)->where('foreign_id', $offer->foreignId)->exists()) {
Log::info('skipped offer: ' . $offer->title);
continue;
}
// log new offer
Log::info('new offer: ' . $offer->title, [
'foreign_id' => $offer->foreignId,
'title' => $offer->title,
'price' => $offer->price,
'flat_size' => $offer->flatSize,
'rooms' => $offer->rooms,
'address' => $offer->address,
]);
// save new offer to database
$dbOffer = Offer::fromOfferDTO($offer);
$dbOffer->save();
// send telegram message
Utils::sendTelegramMessages($offer->toString());
}
Utils::sleepRandomSeconds(2, 20);
}
$browser->quit();