Files
nuhodds_fi4/app/Console/Commands/Grapper/TxOdds/Fixtures.php
T
2025-12-01 21:50:23 +01:00

117 lines
3.9 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\Curl;
use App\Console\Commands\NuhBash;
use App\Models\CompetitionGroup;
use App\Models\Element;
use App\Models\Event;
use App\Models\Group;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Fixtures
{
public static function grap()
{
$debug = NuhBash::$options['d'] ?? 0;
$print = NuhBash::$options['p'] ?? 0;
$break = NuhBash::$options['b'] ?? 0;
$total = 0;
$date = Carbon::now();
for ($i = 0; $i < 30; $i++) {
$from = $date->addDays($i)->toDateString();
$to = $date->addDays($i + 1)->toDateString();
$url = 'https://xml2.txodds.com/feed/result/xml.php?'.config('nuh.txodds_token_soccer')."&date=$from,$to&json=2";
$data = Curl::load($url);
if ($print) {
Notice::note($data, '', 1);
}
$count = 0;
$e = [];
foreach ($data['match'] as $match) {
foreach ($match as $key => $v) {
switch ($key) {
case '@attributes':
$e['txodds_id'] = (int) $v['id'];
break;
case 'time':
$starttime = Carbon::createFromDate($v)->toDateTimeString();
break;
case 'group':
$e['sport_id'] = (int) $v['@attributes']['spid'];
$e['country_id'] = (int) $v['@attributes']['cnid'];
$e['group_id'] = (int) $v['@attributes']['id'];
$e['competition_group_id'] = (int) $v['@attributes']['cgid'];
Group::firstOrCreate([
'txodds_id' => $v['@attributes']['id'],
'competition_group_id' => $e['competition_group_id'],
], [
'name' => (string) $v['@text'],
'sport_id' => $e['sport_id'],
'country_id' => $e['country_id'],
]);
CompetitionGroup::firstOrCreate([
'txodds_id' => $v['@attributes']['cgid'],
'name' => $v['@attributes']['cname'],
'sport_id' => $e['sport_id'],
'country_id' => $e['country_id'],
]);
break;
case 'hteam':
$e['home_id'] = $v['@attributes']['id'];
Element::firstOrCreate([
'txodds_id' => (int) $v['@attributes']['id'],
'name' => $v['@text'],
'sport_id' => $e['sport_id'],
]);
break;
case 'ateam':
$e['away_id'] = $v['@attributes']['id'];
Element::firstOrCreate([
'txodds_id' => (int) $v['@attributes']['id'],
'name' => $v['@text'],
'sport_id' => $e['sport_id'],
]);
break;
}
}
Event::firstOrCreate($e, ['starttime' => $starttime]);
$count++;
}
if ($debug) {
Notice::note("$from - $count events processed", 'g');
}
$total += $count;
if ($break || $debug) {
break;
}
}
Notice::note("Total - $total events processed", 'g');
}
}