txodds grapping odds - wip

This commit is contained in:
salam committed 2025-11-30 08:09:24 +01:00
1 parent 16c5608fd1
commit a597d3161b
27 files changed
+410 -15713

No files matched your search

+7 -7
View File
@@ -22,7 +22,9 @@ class Curl
}
if ($read) {
if ($debug) {
Notice::note('data read local', 'r');
}
switch (NuhBash::$options['filetype']) {
case 'xml':
return simplexml_load_file(self::$file, null, LIBXML_NOCDATA);
@@ -37,11 +39,6 @@ class Curl
Notice::note('filetype unknown', 'r', 1);
}
if ($debug) {
Notice::note('data read local', 'b');
}
}
$ch = curl_init($url);
@@ -54,7 +51,10 @@ class Curl
if ($curl_errorno) {
Notice::note('curl_errorno: '.self::curlerrorcode($curl_errorno));
}
curl_close($ch);
if (PHP_VERSION_ID < 80000) {
curl_close($ch);
}
if ($save) {
Notice::note('data saved', 'b');
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Console\Commands\Grapper;
use App\Utilities\Notice;
class Helper
{
/**
* Create a new class instance.
*/
public static function get_auth_string()
{
if (Grapper::$options['provider_id'] == 1) {
// txodds soccer
Grapper::$auth = 'ident=betaid1&passwd=Dy59vpRC';
Grapper::$domain = 'https://xml2.txodds.com/';
} elseif (Grapper::$options['provider_id'] == 3) {
// txodds others
Grapper::$auth = 'ident=betaid2&passwd=Dy59vpRC';
Grapper::$domain = 'https://xml2.txodds.com/';
} else {
Notice::note('error txodds provider', 'r', 1);
}
}
public static function margin($arr, $stellen = 3)
{
$r = 0;
foreach ($arr as $value) {
$r += 100 / $value;
}
return round($r, $stellen);
}
}
@@ -11,9 +11,9 @@ use App\Models\Event;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class FixturesSoccer
class Fixtures
{
public static function call()
public static function grap()
{
$debug = NuhBash::$options['d'] ?? 0;
$print = NuhBash::$options['p'] ?? 0;
@@ -28,7 +28,7 @@ class FixturesSoccer
$from = $date->addDays($i)->toDateString();
$to = $date->addDays($i + 1)->toDateString();
$url = 'https://xml2.txodds.com/feed/result/xml.php?ident=betaid1&passwd='.config('nuh.txodds_token')."&date=$from,$to&json=2";
$url = 'https://xml2.txodds.com/feed/result/xml.php?'.config('nuh.txodds_token_soccer')."&date=$from,$to&json=2";
$data = Curl::load($url, $debug);
if ($print) {
+238 -106
View File
@@ -2,20 +2,20 @@
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\Grapper\Grapper;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Helper;
use App\Console\Commands\NuhBash;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Utilities\Notice;
use App\Utilities\Supervisorctl;
use Illuminate\Support\Carbon;
use Carbon\Carbon;
class Odds
{
public static function grap()
{
Notice::note('txodd odd sport: '.Grapper::$options['sport_id'], 'b');
Notice::note('txodd odd sport: '.NuhBash::$options['sport_id'], 'b');
/*************************************************
* SINGLE SOCCER
@@ -67,9 +67,9 @@ class Odds
*************************************************/
$debug = Grapper::$options['d'] ?? 0;
$debug = NuhBash::$options['d'] ?? 0;
switch (Grapper::$options['sport_id']) {
switch (NuhBash::$options['sport_id']) {
case 1:
$markets = '0,4,11534337,5242880,7340033';
break;
@@ -95,145 +95,277 @@ class Odds
/*************************************************
* URL
*************************************************/
$url = Grapper::$domain.'feed/odds/xml.php?'.Grapper::$auth.'&all_odds=2&spid='.Grapper::$options['sport_id'];
$url = 'https://xml2.txodds.com/feed/odds/xml.php?'.config('nuh.txodds_token_soccer').'&all_odds=2&spid='.NuhBash::$options['sport_id'].'&json=2';
$_calls = [];
if (Grapper::$options['event_id']) {
$_calls[] = $url."&ot=$markets&peid=".Grapper::$options['event_id'];
} elseif (Grapper::$options['a']) {
if (NuhBash::$options['event_id']) {
$_calls[] = $url."&ot=$markets&peid=".NuhBash::$options['event_id'];
} elseif (NuhBash::$options['a']) {
$res = Event::where('time', '>', Carbon::now()->toDateTimeString())->pluck('txid');
foreach ($res as $id) {
$_calls[] = $url."&ot=$markets&peid=".$id;
}
} elseif (Grapper::$options['w']) {
} elseif (NuhBash::$options['w']) {
$res = Event::where('time', '>', Carbon::now()->toDateTimeString())->where('time', '<', Carbon::now()->addDays(7)->toDateTimeString())->pluck('txid');
foreach ($res as $id) {
$_calls[] = $url."&ot=$markets&peid=".$id;
}
} else {
$_calls[] = $url.'&last='.Grapper::$options['lastcall'];
$_calls[] = $url.'&last='.NuhBash::$options['lastcall'];
}
/*************************************************
* CALL
*************************************************/
foreach ($_calls as $url) {
Notice::note($url, 'r');
$xml = simplexml_load_file($url, null, LIBXML_NOCDATA);
$json_obj = Curl::load($url, $debug);
if (Grapper::$options['p']) {
Notice::note($url);
foreach ($xml->match as $match) {
print_r($match);
}
exit;
}
$e = [];
Supervisorctl::set_lastcall($xml['timestamp']);
foreach ($json_obj['match'] as $key => $v) {
foreach ($xml->match as $m) {
Notice::note($key, 'b');
if (Grapper::$options['d']) {
Notice::note((int) $m['id'].' : '.$m->hteam.' - '.$m->ateam);
}
switch ($key) {
case '@attributes':
$e['id'] = (int) $v['id'];
break;
$evid = Event::where('txid', (int) $m['id'])->pluck('id')->first();
case 'time':
$e['time'] = $v;
break;
if ($evid) {
$fixed_array = [];
$fixed_array['event_id'] = $evid;
case 'group':
$e['group'] = $v['@attributes']['cname'];
$e['gid'] = $v['@attributes']['id'];
$e['cgid'] = $v['@attributes']['cgid'];
$e['spid'] = $v['@attributes']['spid'];
$e['mgid'] = $v['@attributes']['mgid'];
$e['cnid'] = $v['@attributes']['cnid'];
break;
Event::where('id', $evid)->update(['cnt_bkm_tx' => count($m->bookmaker)]);
case 'hteam':
$e['hoid'] = $v['@attributes']['id'];
$e['home'] = $v['@text'];
break;
foreach ($m->bookmaker as $bookmaker) {
case 'ateam':
$e['awid'] = $v['@attributes']['id'];
$e['away'] = $v['@text'];
break;
$fixed_array['bkid'] = (int) $bookmaker['bid'];
case 'bookmaker':
$value_array = [];
foreach ($v as $books) {
foreach ($bookmaker->offer as $offer) {
switch ($offer['ot']) {
case '0':
foreach ($books as $bkey => $book) {
$value_array['f3w'] = (int) $offer['flags'] ?? 0;
$value_array['boid'] = (string) $offer['bmoid'] ?? 0;
$value_array['time'] = Carbon::parse($offer->odds['starting_time'])->toDateTimeString();
switch ($bkey) {
case '@attributes':
$bname = $book['name'];
$bkmid = (int) $book['bid'];
$e['odds'][$bkmid]['name'] = $bname;
break;
case 'offer':
$tmp = [];
$tmp['h3w'] = (float) $offer->odds->o1 ?? 1;
$tmp['d3w'] = (float) $offer->odds->o2 ?? 1;
$tmp['a3w'] = (float) $offer->odds->o3 ?? 1;
$tmp['m3w'] = Helper::margin($tmp);
$value_array += $tmp;
break;
foreach ($book as $offer) {
foreach ($offer as $type => $od) {
case '1':
switch ($type) {
case '@attributes':
$bettypeid = (int) $od['ot'];
$bmoid = $od['bmoid'];
break;
case 'odds':
switch ($bettypeid) {
$value_array['f2w'] = (int) $offer['flags'] ?? 0;
$value_array['boid'] = (string) $offer['bmoid'] ?? 0;
$value_array['time'] = Carbon::parse($offer->odds['starting_time'])->toDateTimeString();
case '0':
// three way
$e['odds_3ways'][] = [
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'matchpart_id' => 1,
'sport_id' => 1,
'bmoid' => $bmoid,
'start' => $od['@attributes']['starting_time'],
'h3w' => (float) $od['o1'],
'd3w' => (float) $od['o2'],
'a3w' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o2'], $od['o3']], 1),
'book_startime' => $od['@attributes']['starting_time'],
'source_updated_at' => $od['@attributes']['time'],
'nuh_last_check' => Carbon::now()->toDateTimeString(),
];
break;
$tmp = [];
$tmp['h2w'] = (float) $offer->odds->o1 ?? 1;
$tmp['a2w'] = (float) $offer->odds->o3 ?? 1;
$tmp['m2w'] = Helper::margin($tmp);
$value_array += $tmp;
break;
case '4':
// totals
$e['odds_totals'][] = [
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'matchpart_id' => 1,
'sport_id' => 1,
'bmoid' => $bmoid,
'over' => (float) $od['o1'],
'under' => (float) $od['o2'],
'spread' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o2']], 1),
'flag' => 1,
'check' => 0,
'book_startime' => $od['@attributes']['starting_time'],
'source_updated_at' => $od['@attributes']['time'],
'nuh_last_check' => Carbon::now()->toDateTimeString(),
];
break;
case '4':
$hc = (float) $offer->odds->o3;
if (Grapper::$options['sport_id'] == 1 && $hc == 2.5) {
$tmp = [];
$tmp['ov'] = (float) $offer->odds->o1 ?? 1;
$tmp['un'] = (float) $offer->odds->o2 ?? 1;
$tmp['mto'] = Helper::margin($tmp);
$tmp['fto'] = (int) $offer->odd['flags'] ?? 0;
$tmp['hc'] = 2.5;
$value_array += $tmp;
}
break;
case '5242880':
// double chance
$e['odds_dc'][] = [
'event_id' => $e['id'],
'bookmaker_id' => $bkmid,
'matchpart_id' => 1,
'sport_id' => 1,
'bmoid' => $bmoid,
'dc1x' => (float) $od['o1'],
'dc12' => (float) $od['o2'],
'dc2x' => (float) $od['o3'],
'margin' => (float) Helper::margin([$od['o1'], $od['o2'], $od['o3']], 1),
'book_startime' => $od['@attributes']['starting_time'],
'source_updated_at' => $od['@attributes']['time'],
'nuh_last_check' => Carbon::now()->toDateTimeString(),
];
break;
}
case '5242880':
// Double Chance (dc1x,dc12,dcx2)
$value_array['fdc'] = (int) $offer['flags'] ?? 0;
$tmp = [];
$tmp['dc1x'] = (float) $offer->odds->o1 ?? 1;
$tmp['dc12'] = (float) $offer->odds->o2 ?? 1;
$tmp['dcx2'] = (float) $offer->odds->o3 ?? 1;
$tmp['mdc'] = Helper::margin($tmp);
$value_array += $tmp;
break;
case '11534337':
// goal/nogoal (gg,ng)
$value_array['fgg'] = (int) $offer['flags'] ?? 0;
$tmp = [];
$tmp['gg'] = (float) $offer->odds->o1 ?? 1;
$tmp['ng'] = (float) $offer->odds->o3 ?? 1;
$tmp['mgg'] = Helper::margin($tmp);
$value_array += $tmp;
break;
case '7340033':
// to qualify (htq,atq)
$value_array['ftq'] = (int) $offer['flags'] ?? 0;
$tmp = [];
$tmp['htq'] = (float) $offer->odds->o1 ?? 1;
$tmp['atq'] = (float) $offer->odds->o3 ?? 1;
$tmp['mtq'] = Helper::margin($tmp);
$value_array += $tmp;
break;
break;
}
}
}
break;
}
}
}
EventBookmaker::updateOrCreate($fixed_array, $value_array);
if (Grapper::$options['d']) {
Notice::note($fixed_array + $value_array, 'b');
}
}
break;
}
}
dd($e);
// if (NuhBash::$options['d']) {
// Notice::note((int) $row['id'].' : '.$row->hteam.' - '.$row->ateam, 'b', 1);
// }
// dd($data);
// if (NuhBash::$options['p']) {
// Notice::note($url);
// foreach ($xml->match as $match) {
// print_r($match);
// }
// exit;
// }
// foreach ($xml->match as $m) {
// if (NuhBash::$options['d']) {
// Notice::note((int) $m['id'].' : '.$m->hteam.' - '.$m->ateam);
// }
// $evid = Event::where('txid', (int) $m['id'])->pluck('id')->first();
// if ($evid) {
// $fixed_array = [];
// $fixed_array['event_id'] = $evid;
// Event::where('id', $evid)->update(['cnt_bkm_tx' => count($m->bookmaker)]);
// foreach ($m->bookmaker as $bookmaker) {
// $fixed_array['bkid'] = (int) $bookmaker['bid'];
// $value_array = [];
// foreach ($bookmaker->offer as $offer) {
// switch ($offer['ot']) {
// case '0':
// $value_array['f3w'] = (int) $offer['flags'] ?? 0;
// $value_array['boid'] = (string) $offer['bmoid'] ?? 0;
// $value_array['time'] = Carbon::parse($offer->odds['starting_time'])->toDateTimeString();
// $tmp = [];
// $tmp['h3w'] = (float) $offer->odds->o1 ?? 1;
// $tmp['d3w'] = (float) $offer->odds->o2 ?? 1;
// $tmp['a3w'] = (float) $offer->odds->o3 ?? 1;
// $tmp['m3w'] = Helper::margin($tmp);
// $value_array += $tmp;
// break;
// case '1':
// $value_array['f2w'] = (int) $offer['flags'] ?? 0;
// $value_array['boid'] = (string) $offer['bmoid'] ?? 0;
// $value_array['time'] = Carbon::parse($offer->odds['starting_time'])->toDateTimeString();
// $tmp = [];
// $tmp['h2w'] = (float) $offer->odds->o1 ?? 1;
// $tmp['a2w'] = (float) $offer->odds->o3 ?? 1;
// $tmp['m2w'] = Helper::margin($tmp);
// $value_array += $tmp;
// break;
// case '4':
// $hc = (float) $offer->odds->o3;
// if (NuhBash::$options['sport_id'] == 1 && $hc == 2.5) {
// $tmp = [];
// $tmp['ov'] = (float) $offer->odds->o1 ?? 1;
// $tmp['un'] = (float) $offer->odds->o2 ?? 1;
// $tmp['mto'] = Helper::margin($tmp);
// $tmp['fto'] = (int) $offer->odd['flags'] ?? 0;
// $tmp['hc'] = 2.5;
// $value_array += $tmp;
// }
// break;
// case '5242880':
// // Double Chance (dc1x,dc12,dcx2)
// $value_array['fdc'] = (int) $offer['flags'] ?? 0;
// $tmp = [];
// $tmp['dc1x'] = (float) $offer->odds->o1 ?? 1;
// $tmp['dc12'] = (float) $offer->odds->o2 ?? 1;
// $tmp['dcx2'] = (float) $offer->odds->o3 ?? 1;
// $tmp['mdc'] = Helper::margin($tmp);
// $value_array += $tmp;
// break;
// case '11534337':
// // goal/nogoal (gg,ng)
// $value_array['fgg'] = (int) $offer['flags'] ?? 0;
// $tmp = [];
// $tmp['gg'] = (float) $offer->odds->o1 ?? 1;
// $tmp['ng'] = (float) $offer->odds->o3 ?? 1;
// $tmp['mgg'] = Helper::margin($tmp);
// $value_array += $tmp;
// break;
// case '7340033':
// // to qualify (htq,atq)
// $value_array['ftq'] = (int) $offer['flags'] ?? 0;
// $tmp = [];
// $tmp['htq'] = (float) $offer->odds->o1 ?? 1;
// $tmp['atq'] = (float) $offer->odds->o3 ?? 1;
// $tmp['mtq'] = Helper::margin($tmp);
// $value_array += $tmp;
// break;
// }
// }
// EventBookmaker::updateOrCreate($fixed_array, $value_array);
// if (NuhBash::$options['d']) {
// Notice::note($fixed_array + $value_array, 'b');
// }
// }
// }
// }
}
}
}
+4 -5
View File
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\TxOdds\Countries;
use App\Console\Commands\Grapper\TxOdds\FixturesSoccer;
use App\Console\Commands\Grapper\TxOdds\Fixtures;
use App\Console\Commands\Grapper\TxOdds\Odds;
use App\Console\Commands\NuhBash;
class TxSwitch
@@ -13,13 +13,12 @@ class TxSwitch
*/
public static function switch()
{
switch (NuhBash::$options['id']) {
case 1:
FixturesSoccer::call();
Fixtures::grap();
break;
case 2:
Countries::call();
Odds::grap();
break;
case 3:
break;