Files
nuhodds_fi4/app/Console/Commands/Grapper/TxOdds/Fixtures.php
T
2025-12-18 19:22:36 +01:00

125 lines
4.1 KiB
PHP

<?php
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\Nuh;
use App\Console\Commands\Xml;
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 = Nuh::$options['d'] ?? 0;
$echo = Nuh::$options['e'] ?? 0;
$break = Nuh::$options['b'] ?? 0;
$count = 0;
$total = 0;
$now = Carbon::now();
/**
* Delete
*/
// $info = 0;
$info = Event::where('starttime', '<', $now->toDateTimeString())->delete();
if ($debug) {
Notice::note("Deleted: $info");
}
/**
* Grap
*/
for ($i = 0; $i < 30; $i++) {
$from = $now->addDays($i)->toDateString();
$to = $now->addDays($i + 1)->toDateString();
$url = 'https://xml2.txodds.com/feed/result/xml.php?'.Nuh::$AUTHTOKEN."&date=$from,$to";
$data = Xml::load($url);
if ($echo) {
dd($data);
}
foreach ($data as $row) {
// <match id="14563695" xsid="0" gsmid="0" last_updated="2025-12-02T08:31:11+00:00">
// <time>2025-12-03T22:30:00+00:00</time>
// <group id="173093" cgid="1255" spid="1" cnid="467" mgid="1002" cname="Reserve League">FBARG Reserve League-25</group>
// <hteam id="187003" >Boca Juniors II</hteam>
// <ateam id="185803" >Gimnasia LP II</ateam>
// <results>
// <status last_updated="2025-12-02T08:31:10+00:00" minute="-1">Sched</status>
// <result id="1" name="CURRENT" value="" />
// </results>
// </match>
$event = [];
$event['tx_id'] = (int) $row['id'];
$event['starttime'] = Carbon::createFromDate((string) $row->time)->toDateTimeString();
$group_name = (string) $row->group;
$event['group_id'] = (int) $row->group['id'];
$event['sport_id'] = (int) $row->group['spid'];
$event['country_id'] = (int) $row->group['cnid'];
$event['competition_group_id'] = (int) $row->group['cgid'];
$competition_group_name = (string) $row->group['cname'];
$home = (string) $row->hteam;
$event['home_id'] = (int) $row->hteam['id'];
$away = (string) $row->ateam;
$event['away_id'] = (int) $row->ateam['id'];
Group::updateOrCreate([
'tx_id' => $event['group_id'],
'competition_group_id' => $event['competition_group_id'],
'sport_id' => $event['sport_id'],
'country_id' => $event['country_id'],
], [
'name' => $group_name,
]);
CompetitionGroup::updateOrCreate([
'tx_id' => $event['competition_group_id'],
'sport_id' => $event['sport_id'],
'country_id' => $event['country_id'],
], [
'name' => $competition_group_name,
]);
Element::firstOrCreate([
'tx_id' => $event['home_id'],
'name' => $home,
'sport_id' => $event['sport_id'],
]);
Element::firstOrCreate([
'tx_id' => $event['away_id'],
'name' => $away,
'sport_id' => $event['sport_id'],
]);
Event::updateOrCreate($event, ['starttime' => $event['starttime']]);
$count++;
}
if ($debug) {
Notice::note("$from - $count events processed", 'g');
}
$total += $count;
if ($break || $debug) {
break;
}
}
if ($debug) {
Notice::note("Total - $total events processed", 'g');
}
}
}