wip fix
This commit is contained in:
1 parent
9bcd4432c6
commit
6f92f9e1d5
1209 files changed
+220940
No files matched your search
@@ -0,0 +1,142 @@
|
||||
<?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\ElementGroup;
|
||||
use App\Models\Event;
|
||||
use App\Models\Group;
|
||||
use App\Models\Sport;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Fixtures
|
||||
{
|
||||
public static function grap()
|
||||
{
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
$today = Nuh::$options['t'] ?? 0;
|
||||
$week = Nuh::$options['w'] ?? 0;
|
||||
|
||||
if ($debug) {
|
||||
Notice::note('TXODDS FIXTURES', 'b');
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$total_soccer = 0;
|
||||
$total_others = 0;
|
||||
|
||||
$sports = Sport::where('is_active', 1)->pluck('id')->toArray();
|
||||
|
||||
/**
|
||||
* Grap
|
||||
*/
|
||||
$kontos = ['soccer' => config('env.txodds_betaid1'), 'other' => config('env.txodds_betaid2')];
|
||||
|
||||
foreach ($kontos as $authentication) {
|
||||
// code...
|
||||
|
||||
if ($today) {
|
||||
Nuh::$options['days_from'] = 0;
|
||||
if (now()->between(today(), today()->addHour())) {
|
||||
Nuh::$options['days_to'] = 2;
|
||||
} else {
|
||||
Nuh::$options['days_to'] = 1;
|
||||
}
|
||||
} elseif ($week) {
|
||||
Nuh::$options['days_from'] = 0;
|
||||
Nuh::$options['days_to'] = 6;
|
||||
}
|
||||
|
||||
for ($i = Nuh::$options['days_from']; $i < Nuh::$options['days_to']; $i++) {
|
||||
|
||||
$url = "https://xml2.txodds.com/feed/result/xml.php?$authentication&days=$i,1";
|
||||
|
||||
$data = Xml::load($url);
|
||||
|
||||
foreach ($data as $row) {
|
||||
|
||||
$sport_id = (int) $row->group['spid'];
|
||||
|
||||
if (in_array($sport_id, $sports)) {
|
||||
|
||||
$event = [
|
||||
'provider_id' => (int) Nuh::$options['provider_id'],
|
||||
'starttime' => Carbon::createFromDate((string) $row->time)->toDateTimeString(),
|
||||
'sport_id' => (int) $sport_id,
|
||||
'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'],
|
||||
];
|
||||
|
||||
DB::transaction(function () use ($event, $row) {
|
||||
Event::updateOrCreate(['id' => (int) $row['id']], $event);
|
||||
|
||||
}, 5);
|
||||
|
||||
$group = [
|
||||
'competition_group_id' => (string) $row->group['cgid'],
|
||||
'sport_id' => (int) $sport_id,
|
||||
'country_id' => (int) $row->group['cnid'],
|
||||
'name' => (string) $row->group['cname'],
|
||||
'fullname' => (string) $row->group,
|
||||
];
|
||||
|
||||
Group::updateOrCreate(['id' => (int) $row->group['id']], $group);
|
||||
|
||||
$compgroup = [
|
||||
'sport_id' => (int) $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) $sport_id,
|
||||
'country_id' => (int) $row->group['cnid'],
|
||||
];
|
||||
Element::updateOrCreate(['id' => (int) $row->hteam['id']], $element);
|
||||
|
||||
$element_group = [
|
||||
'competition_group_id' => (int) $row->group['cgid'],
|
||||
];
|
||||
ElementGroup::updateOrCreate(['element_id' => (int) $row->hteam['id'], 'group_id' => (int) $row->group['id']], $element_group);
|
||||
|
||||
$element = [
|
||||
'name' => (string) $row->ateam,
|
||||
'sport_id' => (int) $sport_id,
|
||||
'country_id' => (int) $row->group['cnid'],
|
||||
];
|
||||
Element::updateOrCreate(['id' => (int) $row->ateam['id']], $element);
|
||||
|
||||
$element_group = [
|
||||
'competition_group_id' => (int) $row->group['cgid'],
|
||||
];
|
||||
ElementGroup::updateOrCreate(['element_id' => (int) $row->ateam['id'], 'group_id' => (int) $row->group['id']], $element_group);
|
||||
|
||||
if ($sport_id == 1) {
|
||||
$total_soccer++;
|
||||
} else {
|
||||
$total_others++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
Notice::note(now()->toDateString()." - $count events processed", 'g');
|
||||
}
|
||||
}
|
||||
if ($debug) {
|
||||
Notice::note("Total Soccer - $total_soccer\nTotal Others - $total_others", 'g');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user