111 lines
3.4 KiB
PHP
111 lines
3.4 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) {
|
|
$event = [
|
|
'provider_id' => (int) Nuh::$options['provider_id'],
|
|
'starttime' => Carbon::createFromDate((string) $row->time)->toDateTimeString(),
|
|
'sport_id' => (int) $row->group['spid'],
|
|
'home_id' => (int) $row->hteam['id'],
|
|
'away_id' => (int) $row->ateam['id'],
|
|
'country_id' => (int) $row->group['cnid'],
|
|
'group_id' => (int) $row->group['id'],
|
|
'competition_group_id' => (int) $row->group['cgid'],
|
|
];
|
|
|
|
Event::updateOrCreate(['id' => (int) $row['id']], $event);
|
|
|
|
$group = [
|
|
'competition_group_id' => (string) $row->group['cgid'],
|
|
'sport_id' => (int) $row->group['spid'],
|
|
'country_id' => (int) $row->group['cnid'],
|
|
'name' => (string) $row->group,
|
|
];
|
|
Group::updateOrCreate(['id' => (int) $row->group['id']], $group);
|
|
|
|
$compgroup = [
|
|
'sport_id' => $event['sport_id'],
|
|
'country_id' => $event['country_id'],
|
|
'name' => (string) $row->group['cname'],
|
|
];
|
|
|
|
CompetitionGroup::updateOrCreate(['id' => (int) $row->group['cgid']], $compgroup);
|
|
|
|
$element = [
|
|
'name' => (string) $row->hteam,
|
|
'sport_id' => (int) $row->group['spid'],
|
|
];
|
|
Element::updateOrCreate(['id' => (int) $row->hteam['id']], $element);
|
|
|
|
$element = [
|
|
'name' => (string) $row->ateam,
|
|
'sport_id' => (int) $row->group['spid'],
|
|
];
|
|
Element::updateOrCreate(['id' => (int) $row->ateam['id']], $element);
|
|
|
|
$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');
|
|
}
|
|
}
|
|
}
|