69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Grapper\Betsapi;
|
|
|
|
use App\Console\Commands\Curl;
|
|
use App\Console\Commands\Nuh;
|
|
use App\Models\Mapper;
|
|
use App\Models\Sport;
|
|
use App\Utilities\Notice;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class Fixtures
|
|
{
|
|
public static function grap()
|
|
{
|
|
$debug = Nuh::$options['d'] ?? 0;
|
|
$test = Nuh::$options['t'] ?? 0;
|
|
$echo = Nuh::$options['e'] ?? 0;
|
|
|
|
$sportmap = Sport::map('bapi');
|
|
|
|
$total = 10;
|
|
foreach ($sportmap as $sport_id => $betsapi_sport_id) {
|
|
$page = 1;
|
|
while ($page <= $total) {
|
|
|
|
$url = "https://api.b365api.com/v3/events/upcoming?sport_id=$betsapi_sport_id&page=$page&skip_esports=1&token=".config('env.betsapi_token');
|
|
|
|
$data = Curl::load($url);
|
|
|
|
$page++;
|
|
|
|
$total = round($data['pager']['total'] / $data['pager']['per_page']);
|
|
|
|
if ($debug) {
|
|
Notice::note("Page: $page \nTotal: $total");
|
|
}
|
|
|
|
if (isset($data['results'])) {
|
|
|
|
foreach ($data['results'] as $row) {
|
|
|
|
$event = [
|
|
'sport_id' => (int) $row['sport_id'],
|
|
'provider_id' => (int) Nuh::$options['provider_id'],
|
|
'starttime' => Carbon::createFromTimestamp((string) $row['time'])->toDateTimeString(),
|
|
'home' => $row['home']['name'] ?? '',
|
|
'home_id' => (int) $row['home']['id'],
|
|
'home_cc' => $row['home']['cc'] ?? '',
|
|
'away' => $row['away']['name'] ?? '',
|
|
'away_id' => (int) $row['away']['id'],
|
|
'away_cc' => $row['away']['cc'] ?? '',
|
|
'group' => $row['league']['name'] ?? '',
|
|
'group_id' => (int) $row['league']['id'] ?? 0,
|
|
'group_cc' => $row['league']['cc'] ?? '',
|
|
];
|
|
|
|
Mapper::updateOrCreate(['betsapi_id' => (int) $row['id']], $event);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($debug) {
|
|
Notice::note('FIRST LOOP', 'g', 1);
|
|
}
|
|
}
|
|
}
|
|
}
|