This commit is contained in:
salam committed 2026-10-04 15:25:03 +02:00
1 parent 9bcd4432c6
commit 6f92f9e1d5
1209 files changed
+220940

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
[docker-compose.yml]
indent_size = 4
+11
View File
@@ -0,0 +1,11 @@
* text=auto eol=lf
*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php
/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
+30
View File
@@ -0,0 +1,30 @@
*.log
.DS_Store
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
/.fleet
/.idea
/.nova
/.phpunit.cache
/.vscode
/.zed
/auth.json
/node_modules
/bootstrap/cache
/public/build
/public/hot
/public/css
/public/js
/public/storage
/storage/*.key
/storage/pail
/vendor
/supervisor
/supervisor/nuh
/storage/sofascore_data
Homestead.json
Homestead.yaml
Thumbs.db
+12213
View File
File diff suppressed because it is too large. Load diff
+34417
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Actions;
use App\Models\Event;
use App\Models\OddsTable;
use Carbon\Carbon;
class AlarmStatistic
{
public static function load()
{
$res = OddsTable::select('name', 'fieldnames')->get();
$fields = [];
foreach ($res as $value) {
$fields[$value->name] = explode(',', $value->fieldnames);
}
$events = Event::with('event_bookmaker')
->where('sport_id', auth()->user()->sport_id)
->where('starttime', '>=', Carbon::now())
->whereHas('event_bookmaker', function ($query) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id);
})
->get();
$arr = [];
foreach ($events as $event) {
$row = $event->event_bookmaker;
// $row = get_object_vars($event->toArray());
foreach ($fields as $table => $names) {
foreach ($names as $name) {
$val = (int) $row[$name];
if ($val) {
if (isset($arr[$table][$val])) {
$arr[$table][$val]++;
} else {
$arr[$table][$val] = 1;
}
}
}
}
}
return $arr;
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Actions;
use App\Models\SofaScoreCategory;
use App\Models\SofaScoreTournament;
use App\Models\StatisticFixtures;
class LoadSofaScoreCategory
{
public static function load()
{
$league_ids = StatisticFixtures::where('sport_id', 1)
->groupBy('league_id')
->pluck('league_id')->toArray();
$res = SofaScoreTournament::with('sofascore_category')->whereIn('tournament_id', $league_ids)->get();
$arr = [];
foreach ($res as $value) {
$arr[$value->sofa_score_category_id] = $value->sofascore_category->name;
}
return $arr;
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Actions;
use App\Models\StatisticFixtures;
class LoadStatisticFixturesLeaguesOptions
{
public static function load(?int $sofascore_category_id = 0)
{
$res = StatisticFixtures::with('league')
->whereHas('league', function ($query) use ($sofascore_category_id) {
$query->where('sofa_score_category_id', $sofascore_category_id);
})
->get();
$arr = [];
foreach ($res as $value) {
$arr[$value->league_id] = $value->league->name;
}
return $arr;
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Actions;
use App\Models\SofaScoreRosa;
use App\Models\StatisticFixtures;
class LoadStatisticFixturesMatchOptions
{
public static function load($league_id = 0)
{
if (! $league_id) {
return [];
}
$team_map = SofaScoreRosa::pluck('ss_team_name', 'ss_team_id')->toArray();
$res = StatisticFixtures::where('league_id', $league_id)->get();
$arr = [];
foreach ($res as $val) {
$arr[$val->id] = $val->starttime->format('Y-m-d H:i').' - '.$team_map[$val->home_id].' vs '.$team_map[$val->away_id];
}
return $arr;
}
}
+123
View File
@@ -0,0 +1,123 @@
<?php
namespace App\Actions;
use App\Models\AlarmLevel;
use App\Models\AlarmSetting;
use App\Models\Bookmaker;
use App\Models\ComparingBookmaker;
use App\Models\MultilineClient;
use App\Models\MultilineSetting;
use App\Models\Sport;
use Filament\Notifications\Notification;
class SettingGeneratorClient
{
public static function run($record)
{
/**************************************************
* 1) ALARM SETTING (client_bookmaker_id)
**************************************************/
$alarm_levels = AlarmLevel::get();
foreach ($record->sport as $sport_id) {
foreach ($record->bookmaker as $client_bookmaker_id) {
$multilines = MultilineSetting::where('sport_id', $sport_id)->get()->pluck('id');
foreach ($multilines as $multiline_id) {
foreach ($alarm_levels as $alarm_level) {
AlarmSetting::firstOrCreate(
['client_bookmaker_id' => $client_bookmaker_id, 'sport_id' => $sport_id, 'multiline_setting_id' => $multiline_id, 'alarm_level_id' => $alarm_level->id],
['alarm_threshold' => $alarm_level->default_threshold]
);
}
}
}
}
/**************************************************
* 2) MULTILINE SLOTS (client_bookmaker_id)
**************************************************/
$bookmaker_slots = [1 => 6, 2 => 30, 3 => 649, 4 => 126];
foreach ($record->sport as $sport_id) {
foreach ($record->bookmaker as $client_bookmaker_id) {
$multilines = MultilineSetting::where('sport_id', $sport_id)->get()->pluck('id');
foreach ($multilines as $multiline_id) {
foreach ($bookmaker_slots as $slot => $bookmaker_id) {
MultilineClient::firstOrCreate(
['client_bookmaker_id' => $client_bookmaker_id, 'sport_id' => $sport_id, 'multiline_setting_id' => $multiline_id, 'position' => $slot],
['bookmaker_id' => $bookmaker_id, 'sort' => $slot, 'disabled' => 0]
);
}
}
}
}
/**************************************************
* 4) COMPARING BOOKMAKER (client_bookmaker_id)
**************************************************/
$bookmakers_soccer = Bookmaker::where('in_soccer', 1)->orderBy('name')->pluck('id')->toArray();
ComparingBookmaker::where('method_id', 1)->where('sport_id', 1)->whereNotIn('bookmaker_id', $bookmakers_soccer)->delete();
foreach ($record as $client) {
foreach ($record->bookmaker as $client_bookmaker_id) {
$i = 1;
foreach ($bookmakers_soccer as $bookmaker_id) {
$margin_threshold = $bookmaker_id == 110 ? 103 : 115;
ComparingBookmaker::updateOrCreate(
['method_id' => 1, 'sport_id' => 1, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id],
['is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => $margin_threshold, 'sorting' => $i]
);
$i++;
}
}
}
$sports = Sport::getActiveSports();
if (($key = array_search(1, $sports)) !== false) {
unset($sports[$key]);
}
$bookmakers_other = Bookmaker::where('in_other', 1)->orderBy('name')->pluck('id')->toArray();
ComparingBookmaker::where('method_id', 1)->whereIn('sport_id', $sports)->whereNotIn('bookmaker_id', $bookmakers_other)->delete();
foreach ($record as $client) {
foreach ($record->bookmaker as $client_bookmaker_id) {
foreach ($sports as $sport_id) {
$i = 1;
foreach ($bookmakers_other as $bookmaker_id) {
ComparingBookmaker::updateOrCreate(
['method_id' => 1, 'sport_id' => $sport_id, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id],
['is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => 110, 'sorting' => $i]
);
$i++;
}
}
}
}
Notification::make()
->title('Settings generated successfully')
->success()
->send();
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace App\Actions;
use App\Models\AlarmLevel;
use App\Models\BettypeUser;
use App\Models\Client;
use App\Models\MultilineSetting;
use App\Models\PersonalNotification;
use App\Models\Sport;
use App\Models\User;
use Filament\Notifications\Notification;
class SettingGeneratorUser
{
public static function run($record)
{
User::where('id', $record->id)->update(['all_only_none' => 1]);
/**************************************************
* 3) BETTYPES for USER in MONITOR
**************************************************/
$multilines = MultilineSetting::orderBy('sport_id')->get();
foreach ($multilines as $multiline) {
$is_active = in_array($multiline->id, [1, 2, 9, 10, 16, 17, 22, 23]) ? 1 : 0;
BettypeUser::updateOrCreate(
['sport_id' => $multiline->sport_id, 'user_id' => $record->id, 'multiline_setting_id' => $multiline->id],
['is_active' => $multiline->is_active, 'sorting' => $multiline->sorting],
);
}
/**************************************************
* 5) ALARM NOTIFICATION SETTINGS FOR USERS
**************************************************/
if (in_array($record->id, [1, 2])) {
$sports = Sport::where('is_active', 1)->pluck('id')->toArray();
} else {
$sports = Client::find($record->client_id)->value('sport');
}
$alarm_levels = AlarmLevel::get();
foreach ($alarm_levels as $alarm_level) {
PersonalNotification::firstOrCreate(
['user_id' => $record->id, 'bookmaker_id' => $record->bookmaker_id, 'alarm_level_id' => $alarm_level->id],
['notify_by_system' => 0, 'notify_by_email' => 0]
);
if ($record->partner_bookmaker_id) {
PersonalNotification::firstOrCreate(
['user_id' => $record->id, 'bookmaker_id' => $record->partner_bookmaker_id, 'alarm_level_id' => $alarm_level->id],
['notify_by_system' => 0, 'notify_by_email' => 0]
);
}
}
Notification::make()
->title('Settings for user generated successfully')
->success()
->send();
}
}
+79
View File
@@ -0,0 +1,79 @@
<?php
namespace App\Actions;
use App\Models\Supervisor;
use App\Utilities\Notice;
use Illuminate\Filesystem\Filesystem;
class SupervisorMaker
{
public static $base = '';
public static $path = '';
public static function run($supervisor)
{
$supervisors = Supervisor::all();
$path = base_path().'/supervisor/nuh';
if (! is_dir($path)) {
mkdir($path, 0777);
}
$file = new Filesystem;
$file->cleanDirectory($path);
foreach ($supervisors as $supervisor) {
$parts = [];
$parts[] = 'p'.$supervisor->id;
if (isset($supervisor->sport->name)) {
$parts[] = self::fix_string($supervisor->sport->name);
} else {
$parts[] = 'all';
}
$parts[] = self::fix_string($supervisor->provider->name);
if ($supervisor->name) {
$parts[] = self::fix_string($supervisor->name);
}
if ($supervisor->days_to) {
$parts[] = 'day'.$supervisor->days_from;
$parts[] = 'day'.$supervisor->days_to;
}
$process = strtolower(implode('_', $parts));
$content = '[program:'.$process.']'.PHP_EOL;
if ($supervisor->commandline_options != '') {
$content .= 'command=/usr/bin/php '.base_path().'/artisan nuh '.$supervisor->id.' '.$supervisor->commandline_options.PHP_EOL;
} else {
$content .= 'command=/usr/bin/php '.base_path().'/artisan nuh '.$supervisor->id.PHP_EOL;
}
$content .= 'autostart=true'.PHP_EOL;
$content .= 'autorestart=true'.PHP_EOL;
$file = $path.'/'.$process.'.ini';
if ($supervisor->is_active && $supervisor->is_supervisor) {
file_put_contents($file, $content);
chmod($file, 0777);
}
}
if (config('env.app_env') == 'production') {
$exec = base_path().'/supervisor/super_update.sh';
exec($exec, $out, $rcode);
}
Notice::note('SUPERVISOR '.\count($supervisors).' PROCESSES UPDATED', 'b', 1);
}
public static function fix_string($string)
{
$string = preg_replace("'\W'", '_', $string);
return strtolower($string);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Actions;
use App\Models\Supervisor;
use Filament\Notifications\Notification;
class SupervisorStatus
{
public static function set($status = 0)
{
Supervisor::query()->update(['is_active' => $status]);
if ($status) {
Notification::make()
->title('All supervisors started successfully')
->success()
->send();
} else {
Notification::make()
->title('All supervisors stopped successfully')
->success()
->send();
}
}
}
+230
View File
@@ -0,0 +1,230 @@
<?php
namespace App\Console\Commands;
use App\Utilities\Notice;
class Curl
{
public static $testfiles = '/Console/Commands/TestFiles/';
public static function load($url, $_config = [])
{
$debug = Nuh::$options['d'] ?? 0;
$save = Nuh::$options['s'] ?? 0;
$read = Nuh::$options['r'] ?? 0;
$proxy = Nuh::$options['p'] ?? 0;
if ($debug) {
if ($proxy) {
Notice::note($url . PHP_EOL . Nuh::$options['proxy'], 'b');
} else {
Notice::note($url, 'g');
}
}
if ($read) {
if ($debug) {
Notice::note('data read localy', 'g');
}
$filename = app_path() . self::$testfiles . strtolower(str_replace(' ', '_', Nuh::$options['name'])) . '.json';
$file = file_get_contents($filename);
return json_decode($file, true);
}
$file = self::fetch_data_with_retries($url, $_config);
if ($save) {
$filename = app_path() . self::$testfiles . strtolower(str_replace(' ', '_', Nuh::$options['name'])) . '.json';
file_put_contents($filename, $file);
Notice::note('file saved localy', 'g');
}
$data = json_decode($file, true);
switch (json_last_error()) {
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
}
return $data;
}
public static function fetch_data_with_retries($url, $_config = [], $max_retries = 3)
{
$attempt = 0;
$timeout = 10;
$connect_timeout = 5; // seconds
if (isset($_config['timeout'])) {
$timeout = $_config['timeout'];
}
$debug = Nuh::$options['d'] ?? 0;
$proxy = Nuh::$options['p'] ?? 0;
while ($attempt < $max_retries) {
if ($proxy) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Nuh::$options['proxy']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // Total timeout
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connect_timeout); // Connection timeout
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
if (isset($_config['post'])) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $_config['post']);
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, ['url' => $url]);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Proxy-Auth: AIkcoRnipSgMK88WMQhOQQN3LKDrNDCIebNfPnEayJdmDeTigx',
]);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // Total timeout
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connect_timeout); // Connection timeout
curl_setopt($ch, CURLOPT_FAILONERROR, true);
// POST
if (isset($_config['post'])) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($_config['post']));
}
// JSON
if (isset($_config['header'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $_config['header']);
}
}
$response = curl_exec($ch);
if ($response === false) {
$attempt++;
$curl_errorno = curl_errno($ch);
if ($debug && $curl_errorno) {
Notice::note('curl_errorno: ' . self::curlerrorcode($curl_errorno));
}
if ($debug) {
echo "Attempt $attempt failed. Retrying...\n";
}
sleep(2); // Optional: Sleep between retries
} else {
return $response;
}
}
echo "All attempts failed.\n";
return null; // Return null if all retries fail
}
public static function curlerrorcode($id)
{
$error_codes = [
1 => 'CURLE_UNSUPPORTED_PROTOCOL',
2 => 'CURLE_FAILED_INIT',
3 => 'CURLE_URL_MALFORMAT',
4 => 'CURLE_URL_MALFORMAT_USER',
5 => 'CURLE_COULDNT_RESOLVE_PROXY',
6 => 'CURLE_COULDNT_RESOLVE_HOST',
7 => 'CURLE_COULDNT_CONNECT',
8 => 'CURLE_FTP_WEIRD_SERVER_REPLY',
9 => 'CURLE_REMOTE_ACCESS_DENIED',
11 => 'CURLE_FTP_WEIRD_PASS_REPLY',
13 => 'CURLE_FTP_WEIRD_PASV_REPLY',
14 => 'CURLE_FTP_WEIRD_227_FORMAT',
15 => 'CURLE_FTP_CANT_GET_HOST',
17 => 'CURLE_FTP_COULDNT_SET_TYPE',
18 => 'CURLE_PARTIAL_FILE',
19 => 'CURLE_FTP_COULDNT_RETR_FILE',
21 => 'CURLE_QUOTE_ERROR',
22 => 'CURLE_HTTP_RETURNED_ERROR',
23 => 'CURLE_WRITE_ERROR',
25 => 'CURLE_UPLOAD_FAILED',
26 => 'CURLE_READ_ERROR',
27 => 'CURLE_OUT_OF_MEMORY',
28 => 'CURLE_OPERATION_TIMEDOUT',
30 => 'CURLE_FTP_PORT_FAILED',
31 => 'CURLE_FTP_COULDNT_USE_REST',
33 => 'CURLE_RANGE_ERROR',
34 => 'CURLE_HTTP_POST_ERROR',
35 => 'CURLE_SSL_CONNECT_ERROR',
36 => 'CURLE_BAD_DOWNLOAD_RESUME',
37 => 'CURLE_FILE_COULDNT_READ_FILE',
38 => 'CURLE_LDAP_CANNOT_BIND',
39 => 'CURLE_LDAP_SEARCH_FAILED',
41 => 'CURLE_FUNCTION_NOT_FOUND',
42 => 'CURLE_ABORTED_BY_CALLBACK',
43 => 'CURLE_BAD_FUNCTION_ARGUMENT',
45 => 'CURLE_INTERFACE_FAILED',
47 => 'CURLE_TOO_MANY_REDIRECTS',
48 => 'CURLE_UNKNOWN_TELNET_OPTION',
49 => 'CURLE_TELNET_OPTION_SYNTAX',
51 => 'CURLE_PEER_FAILED_VERIFICATION',
52 => 'CURLE_GOT_NOTHING',
53 => 'CURLE_SSL_ENGINE_NOTFOUND',
54 => 'CURLE_SSL_ENGINE_SETFAILED',
55 => 'CURLE_SEND_ERROR',
56 => 'CURLE_RECV_ERROR',
58 => 'CURLE_SSL_CERTPROBLEM',
59 => 'CURLE_SSL_CIPHER',
60 => 'CURLE_SSL_CACERT',
61 => 'CURLE_BAD_CONTENT_ENCODING',
62 => 'CURLE_LDAP_INVALID_URL',
63 => 'CURLE_FILESIZE_EXCEEDED',
64 => 'CURLE_USE_SSL_FAILED',
65 => 'CURLE_SEND_FAIL_REWIND',
66 => 'CURLE_SSL_ENGINE_INITFAILED',
67 => 'CURLE_LOGIN_DENIED',
68 => 'CURLE_TFTP_NOTFOUND',
69 => 'CURLE_TFTP_PERM',
70 => 'CURLE_REMOTE_DISK_FULL',
71 => 'CURLE_TFTP_ILLEGAL',
72 => 'CURLE_TFTP_UNKNOWNID',
73 => 'CURLE_REMOTE_FILE_EXISTS',
74 => 'CURLE_TFTP_NOSUCHUSER',
75 => 'CURLE_CONV_FAILED',
76 => 'CURLE_CONV_REQD',
77 => 'CURLE_SSL_CACERT_BADFILE',
78 => 'CURLE_REMOTE_FILE_NOT_FOUND',
79 => 'CURLE_SSH',
80 => 'CURLE_SSL_SHUTDOWN_FAILED',
81 => 'CURLE_AGAIN',
82 => 'CURLE_SSL_CRL_BADFILE',
83 => 'CURLE_SSL_ISSUER_ERROR',
84 => 'CURLE_FTP_PRET_FAILED',
85 => 'CURLE_RTSP_CSEQ_ERROR',
86 => 'CURLE_RTSP_SESSION_ERROR',
87 => 'CURLE_FTP_BAD_FILE_LIST',
88 => 'CURLE_CHUNK_FAILED',
89 => 'CURLE_NO_CONNECTION_AVAILABLE',
90 => 'CURLE_SSL_PINNEDPUBKEYNOTMATCH',
91 => 'CURLE_SSL_INVALIDCERTSTATUS',
92 => 'CURLE_HTTP2_STREAM',
];
return $error_codes[$id];
}
}
@@ -0,0 +1,36 @@
<?php
namespace App\Console\Commands\DbMapper;
use App\Console\Commands\Nuh;
use App\Utilities\Notice;
class AutoMapper
{
public static function switch()
{
$debug = Nuh::$options['d'] ?? 0;
switch (Nuh::$options['name']) {
case 'Bet365':
Bet365All::run();
break;
case 'MAGLOO KENIA':
MaglooKeniaAll::run();
break;
case 'MAGLOO NIGERIA':
MaglooNigeriaAll::run();
break;
case 'LOGIFUTURE NIGERA':
LogifutureNigeriaAll::run();
break;
case 'LOGIFUTURE COLOMBIA':
LogifutureColombiaAll::run();
break;
default:
Notice::note(Nuh::$options['name'].' '.Nuh::$options['sport'].' not implemented', 'r', 1);
break;
}
}
}
@@ -0,0 +1,86 @@
<?php
namespace App\Console\Commands\DbMapper;
use App\Console\Commands\DbMapper\Helper\FindCompetitionGroup;
use App\Console\Commands\DbMapper\Helper\FindElement;
use App\Console\Commands\DbMapper\Store\StoreElement;
use App\Console\Commands\DbMapper\Store\StoreGroup;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Models\Sport;
use App\Utilities\Notice;
use Carbon\Carbon;
class Bet365All
{
/**
* Provider ID 2
*/
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note(Nuh::$options['name'], 'g');
}
$sports = Sport::getActiveSports();
foreach ($sports as $sport_id) {
$mappers = Mapper::where('provider_id', 2)->where('sport_id', $sport_id)->where('starttime', '>=', Carbon::now())->where('starttime', '<', Carbon::now()->addDays(10))->get()->toArray();
foreach ($mappers as $mapper) {
FindElement::run($mapper);
FindCompetitionGroup::run($mapper);
if ($debug) {
Notice::note($mapper, 'b');
}
if ($mapper['txodds_home_id'] && $mapper['txodds_away_id'] && $mapper['txodds_group_id']) {
$from = Carbon::createFromDate($mapper['starttime'])->subDay();
$to = Carbon::createFromDate($mapper['starttime'])->addDay();
$event = Event::where('starttime', '>', $from)
->where('starttime', '<', $to)
->where('home_id', $mapper['txodds_home_id'])
->where('away_id', $mapper['txodds_away_id'])
->where('competition_group_id', $mapper['txodds_group_id'])
->first();
if ($event) {
StoreElement::store($mapper);
StoreGroup::store($mapper);
$arr = [];
if ($mapper['bet365_id']) {
$arr['bet365_id'] = $mapper['bet365_id'];
}
if ($mapper['betradar_id']) {
$arr['betradar_id'] = $mapper['betradar_id'];
}
if ($mapper['betsapi_id']) {
$arr['betsapi_id'] = $mapper['betsapi_id'];
}
if ($arr) {
Event::where('id', $event->id)->update($arr);
Mapper::where('id', $mapper['id'])->delete();
}
if ($debug) {
Notice::note($event->toArray(), 'g');
}
}
}
}
}
}
}
@@ -0,0 +1,53 @@
<?php
namespace App\Console\Commands\DbMapper\Helper;
class ArrayFunction
{
public static function remove($array, $value = [])
{
$tmp = str_replace(',', ' ', $str);
// $tmp = str_replace('-', ' ', $tmp);
$tmp = str_replace('/', ' ', $tmp);
$tmp = preg_replace('"\([^\)]*\)"', '', $tmp);
$tmp = preg_replace('/[^a-zA-Z0-9 ] /', '', $tmp);
$tmp = str_replace(' ', ' ', $tmp);
$elements = explode(' ', $tmp);
$_return = [];
foreach ($elements as $value) {
if (\strlen($value) > 3) {
$_return[] = $value;
}
}
usort($_return, function ($a, $b) {
return strlen($b) <=> strlen($a);
});
$remove = [
'fc',
'city',
'new',
'real',
'united',
'dinamo',
'town',
'club',
'union',
'sport',
'sports',
'basket',
'hapoel',
'maccabi',
'east'];
return array_diff($_return, $remove);
}
}
@@ -0,0 +1,53 @@
<?php
namespace App\Console\Commands\DbMapper\Helper;
class ExplodeString
{
public static function grap($str)
{
$tmp = str_replace(',', ' ', $str);
// $tmp = str_replace('-', ' ', $tmp);
$tmp = str_replace('/', ' ', $tmp);
$tmp = preg_replace('"\([^\)]*\)"', '', $tmp);
$tmp = preg_replace('/[^a-zA-Z0-9 ] /', '', $tmp);
$tmp = str_replace(' ', ' ', $tmp);
$elements = explode(' ', $tmp);
$_return = [];
foreach ($elements as $value) {
if (\strlen($value) > 3) {
$_return[] = $value;
}
}
usort($_return, function ($a, $b) {
return strlen($b) <=> strlen($a);
});
$remove = [
'fc',
'city',
'new',
'real',
'united',
'dinamo',
'town',
'club',
'union',
'sport',
'sports',
'basket',
'hapoel',
'maccabi',
'east'];
return array_diff($_return, $remove);
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Console\Commands\DbMapper\Helper;
use App\Models\CompetitionGroup;
use App\Models\CompetitionGroupProvider;
class FindCompetitionGroup
{
public static function run(&$mapper)
{
if (isset($mapper['group_id'])) {
$mapper['txodds_group_id'] = CompetitionGroupProvider::where('provider_id', $mapper['provider_id'])
->where('provider_group_id', $mapper['group_id'])->value('competition_group_id');
}
if (! $mapper['txodds_group_id']) {
$arr = ExplodeString::grap($mapper['group']);
$mapper['txodds_group_id'] = CompetitionGroup::where('sport_id', $mapper['sport_id'])
->where(function ($query) use ($arr) {
foreach ($arr as $str) {
$query->where('name', 'like', '%'.$str.'%');
}
})->value('id');
}
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Console\Commands\DbMapper\Helper;
use App\Models\CompetitionGroupProvider;
class FindCompetitionGroupById
{
public static function run(&$mapper)
{
if (isset($mapper['group_id'])) {
$mapper['txodds_group_id'] = CompetitionGroupProvider::where('provider_id', $mapper['provider_id'])
->where('provider_group_id', $mapper['group_id'])->value('competition_group_id');
}
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Console\Commands\DbMapper\Helper;
use App\Models\CountriesItalian;
use App\Models\Country;
class FindCountry
{
public static function run(&$event)
{
if ($event['provider_id'] == 10) {
// GOLDBET
$country = CountriesItalian::where('it', $event['country'])->value('en');
$event['txodds_country_id'] = Country::where('name', $country)->value('id');
} else {
$country = self::fix_country($event['country']);
$event['txodds_country_id'] = Country::where('name', $country)->value('id');
}
}
public static function fix_country($country)
{
switch ($country) {
case 'Internazionale':
case 'International Club':
case 'Internazionali Di Club':
case 'FIBA Intercontinental Cup':
return 'International';
case 'Euro Cup':
case 'Euro Cup Women':
case 'Euroleague':
case 'Euroleague Women':
return 'Europe';
case 'WNBA':
return 'USA';
default:
return $country;
}
}
}
@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands\DbMapper\Helper;
use App\Models\Element;
use App\Models\ElementProvider;
class FindElement
{
public static function run(&$mapper)
{
if (isset($mapper['home_id']) && $mapper['home_id'] > 0) {
$mapper['txodds_home_id'] = ElementProvider::where('provider_id', $mapper['provider_id'])
->where('provider_element_id', $mapper['home_id'])->value('element_id');
}
if (! isset($mapper['txodds_home_id'])) {
$arr = ExplodeString::grap($mapper['home']);
$mapper['txodds_home_id'] = Element::where('sport_id', $mapper['sport_id'])
->where(function ($query) use ($arr) {
foreach ($arr as $str) {
$query->where('name', 'like', '%'.$str.'%');
}
})->value('id');
}
if (isset($mapper['away_id']) && $mapper['away_id'] > 0) {
$mapper['txodds_away_id'] = ElementProvider::where('provider_id', $mapper['provider_id'])
->where('provider_element_id', $mapper['away_id'])->value('element_id');
}
if (! isset($mapper['txodds_away_id'])) {
$arr = ExplodeString::grap($mapper['away']);
$mapper['txodds_away_id'] = Element::where('sport_id', $mapper['sport_id'])
->where(function ($query) use ($arr) {
foreach ($arr as $str) {
$query->where('name', 'like', '%'.$str.'%');
}
})->value('id');
}
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Console\Commands\DbMapper\Helper;
use App\Models\ElementProvider;
class FindElementById
{
public static function run(&$mapper)
{
if (isset($mapper['home_id']) && $mapper['home_id'] > 0) {
$mapper['txodds_home_id'] = ElementProvider::where('provider_id', $mapper['provider_id'])
->where('provider_element_id', $mapper['home_id'])->value('element_id');
}
if (isset($mapper['away_id']) && $mapper['away_id'] > 0) {
$mapper['txodds_away_id'] = ElementProvider::where('provider_id', $mapper['provider_id'])
->where('provider_element_id', $mapper['away_id'])->value('element_id');
}
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Console\Commands\DbMapper\Helper;
use App\Models\CompetitionGroupProvider;
use App\Models\Group;
class FindGroup
{
public static function run(&$mapper)
{
if (isset($mapper['group_id'])) {
$mapper['competition_group_id'] = CompetitionGroupProvider::where('provider_id', $mapper['provider_id'])
->where('provider_group_id', $mapper['group_id'])->value('competition_group_id');
}
if (! $mapper['competition_group_id']) {
$arr = ExplodeString::grap($mapper['group']);
$arr = array_diff($arr, ['Singles', 'ATP', 'WTA']);
$mapper['competition_group_id'] = Group::where('sport_id', $mapper['sport_id'])
->where('competition_group_id', '>', 0)
->where(function ($query) use ($arr) {
foreach ($arr as $str) {
$query->where('name', 'like', '%'.$str.'%');
}
})->value('competition_group_id');
}
}
}
@@ -0,0 +1,80 @@
<?php
namespace App\Console\Commands\DbMapper;
use App\Console\Commands\DbMapper\Helper\FindCompetitionGroup;
use App\Console\Commands\DbMapper\Helper\FindElement;
use App\Console\Commands\DbMapper\Store\StoreElement;
use App\Console\Commands\DbMapper\Store\StoreGroup;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Utilities\Notice;
use Carbon\Carbon;
class LogifutureColombiaAll
{
/**
* Provider ID 2
*/
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note(Nuh::$options['name'].' '.Nuh::$options['sport'], 'g');
}
$mappers = Mapper::where('provider_id', 2)->where('sport_id', 5)->where('starttime', '>=', Carbon::now())->get()->toArray();
foreach ($mappers as $mapper) {
FindElement::run($mapper);
FindCompetitionGroup::run($mapper);
if ($debug) {
Notice::note($mapper, 'b');
}
if ($mapper['txodds_home_id'] && $mapper['txodds_away_id'] && $mapper['txodds_group_id']) {
$from = Carbon::createFromDate($mapper['starttime'])->subDay();
$to = Carbon::createFromDate($mapper['starttime'])->addDay();
$event = Event::where('starttime', '>', $from)
->where('starttime', '<', $to)
->where('home_id', $mapper['txodds_home_id'])
->where('away_id', $mapper['txodds_away_id'])
->where('competition_group_id', $mapper['txodds_group_id'])
->first();
if ($event) {
StoreElement::store($mapper);
StoreGroup::store($mapper);
$arr = [];
if ($mapper['bet365_id']) {
$arr['bet365_id'] = $mapper['bet365_id'];
}
if ($mapper['betradar_id']) {
$arr['betradar_id'] = $mapper['betradar_id'];
}
if ($mapper['betsapi_id']) {
$arr['betsapi_id'] = $mapper['betsapi_id'];
}
if ($arr) {
Event::where('id', $event->id)->update($arr);
Mapper::where('id', $mapper['id'])->delete();
}
if ($debug) {
Notice::note($event->toArray(), 'g');
}
}
}
}
}
}
@@ -0,0 +1,94 @@
<?php
namespace App\Console\Commands\DbMapper;
use App\Console\Commands\DbMapper\Helper\FindElement;
use App\Console\Commands\DbMapper\Helper\FindGroup;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Models\Sport;
use App\Utilities\Notice;
use Carbon\Carbon;
class LogifutureNigeriaAll
{
/**
* Provider ID 5
* LOGIFUTURE NIGERA
*/
public static function run()
{
$provider_id = 5;
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note(Nuh::$options['name'], 'g');
}
$sports = Sport::getActiveSports();
$found = [];
foreach ($sports as $sport_id) {
$mappers = Mapper::where('provider_id', $provider_id)->where('sport_id', $sport_id)->where('starttime', '>=', Carbon::now())->get()->toArray();
foreach ($mappers as $mapper) {
FindElement::run($mapper);
FindGroup::run($mapper);
if ($debug) {
Notice::note($mapper, 'p');
}
if (isset($mapper['txodds_home_id']) && isset($mapper['txodds_away_id']) && isset($mapper['competition_group_id'])) {
$from = Carbon::createFromDate($mapper['starttime'])->subDay();
$to = Carbon::createFromDate($mapper['starttime'])->addDay();
$event = Event::where('starttime', '>', $from)
->where('starttime', '<', $to)
->where('home_id', $mapper['txodds_home_id'])
->where('away_id', $mapper['txodds_away_id'])
->where('competition_group_id', $mapper['competition_group_id'])
->first();
if ($event) {
if (! isset($found[$sport_id])) {
$found[$sport_id] = 1;
} else {
$found[$sport_id]++;
}
$arr = [];
if ($mapper['bet365_id']) {
$arr['bet365_id'] = $mapper['bet365_id'];
}
if ($mapper['betradar_id']) {
$arr['betradar_id'] = $mapper['betradar_id'];
}
if ($mapper['betsapi_id']) {
$arr['betsapi_id'] = $mapper['betsapi_id'];
}
if ($arr) {
Event::where('id', $event->id)->update($arr);
Mapper::where('id', $mapper['id'])->delete();
}
if ($debug) {
Notice::note($event->toArray(), 'g');
}
}
}
}
}
if ($debug) {
Notice::note($found, 'g');
}
}
}
@@ -0,0 +1,100 @@
<?php
namespace App\Console\Commands\DbMapper;
use App\Console\Commands\DbMapper\Helper\FindCompetitionGroupById;
use App\Console\Commands\DbMapper\Helper\FindElementById;
use App\Console\Commands\DbMapper\Store\StoreElement;
use App\Console\Commands\DbMapper\Store\StoreGroup;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Utilities\Notice;
use Carbon\Carbon;
class MaglooKeniaAll
{
/**
* Provider Id 3
*/
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
$provider_id = 3;
if ($debug) {
Notice::note(Nuh::$options['name'], 'g');
}
$sports = [1, 3];
$found = [];
foreach ($sports as $sport_id) {
$mappers = Mapper::where('provider_id', $provider_id)->where('sport_id', $sport_id)->where('starttime', '>=', Carbon::now())->get()->toArray();
foreach ($mappers as $mapper) {
FindElementById::run($mapper);
FindCompetitionGroupById::run($mapper);
if ($debug) {
Notice::note($mapper, 'p');
}
if ($mapper['txodds_home_id'] && $mapper['txodds_away_id'] && $mapper['txodds_group_id']) {
$from = Carbon::createFromDate($mapper['starttime'])->subDay();
$to = Carbon::createFromDate($mapper['starttime'])->addDay();
$event = Event::where('starttime', '>', $from)
->where('starttime', '<', $to)
->where('home_id', $mapper['txodds_home_id'])
->where('away_id', $mapper['txodds_away_id'])
->where('competition_group_id', $mapper['txodds_group_id'])
->first();
if ($event) {
if ($debug) {
Notice::note($event, 'g');
}
if (! isset($found[$sport_id])) {
$found[$sport_id] = 1;
} else {
$found[$sport_id]++;
}
StoreElement::store($mapper);
StoreGroup::store($mapper);
$arr = [];
if ($mapper['bet365_id']) {
$arr['bet365_id'] = $mapper['bet365_id'];
}
if ($mapper['betradar_id']) {
$arr['betradar_id'] = $mapper['betradar_id'];
}
if ($mapper['betsapi_id']) {
$arr['betsapi_id'] = $mapper['betsapi_id'];
}
if ($arr) {
Event::where('id', $event->id)->update($arr);
Mapper::where('id', $mapper['id'])->delete();
}
}
}
}
}
if ($debug) {
Notice::note($found, 'g');
}
}
}
@@ -0,0 +1,100 @@
<?php
namespace App\Console\Commands\DbMapper;
use App\Console\Commands\DbMapper\Helper\FindCompetitionGroupById;
use App\Console\Commands\DbMapper\Helper\FindElementById;
use App\Console\Commands\DbMapper\Store\StoreElement;
use App\Console\Commands\DbMapper\Store\StoreGroup;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Utilities\Notice;
use Carbon\Carbon;
class MaglooNigeriaAll
{
/**
* Provider Id 4
*/
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
$provider_id = 4;
if ($debug) {
Notice::note(Nuh::$options['name'], 'g');
}
$sports = [1, 3];
$found = [];
foreach ($sports as $sport_id) {
$mappers = Mapper::where('provider_id', $provider_id)->where('sport_id', $sport_id)->where('starttime', '>=', Carbon::now())->get()->toArray();
foreach ($mappers as $mapper) {
FindElementById::run($mapper);
FindCompetitionGroupById::run($mapper);
if ($debug) {
Notice::note($mapper, 'p');
}
if ($mapper['txodds_home_id'] && $mapper['txodds_away_id'] && $mapper['txodds_group_id']) {
$from = Carbon::createFromDate($mapper['starttime'])->subDay();
$to = Carbon::createFromDate($mapper['starttime'])->addDay();
$event = Event::where('starttime', '>', $from)
->where('starttime', '<', $to)
->where('home_id', $mapper['txodds_home_id'])
->where('away_id', $mapper['txodds_away_id'])
->where('competition_group_id', $mapper['txodds_group_id'])
->first();
if ($event) {
if ($debug) {
Notice::note($event, 'g');
}
if (! isset($found[$sport_id])) {
$found[$sport_id] = 1;
} else {
$found[$sport_id]++;
}
StoreElement::store($mapper);
StoreGroup::store($mapper);
$arr = [];
if ($mapper['bet365_id']) {
$arr['bet365_id'] = $mapper['bet365_id'];
}
if ($mapper['betradar_id']) {
$arr['betradar_id'] = $mapper['betradar_id'];
}
if ($mapper['betsapi_id']) {
$arr['betsapi_id'] = $mapper['betsapi_id'];
}
if ($arr) {
Event::where('id', $event->id)->update($arr);
Mapper::where('id', $mapper['id'])->delete();
}
}
}
}
}
if ($debug) {
Notice::note($found, 'g');
}
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Console\Commands\DbMapper\Store;
use App\Models\ElementProvider;
class StoreElement
{
public static function store(&$mapper)
{
$home = [];
$home['sport_id'] = $mapper['sport_id'];
$home['element_id'] = $mapper['txodds_home_id'];
$home['provider_id'] = $mapper['provider_id'];
$home['add_by_method_id'] = 3;
$home['name'] = $mapper['home'];
ElementProvider::updateOrCreate(['provider_element_id' => (int) $mapper['home_id']], $home);
$away = [];
$away['sport_id'] = $mapper['sport_id'];
$away['element_id'] = $mapper['txodds_away_id'];
$away['provider_id'] = $mapper['provider_id'];
$home['add_by_method_id'] = 3;
$away['name'] = $mapper['away'];
ElementProvider::updateOrCreate(['provider_element_id' => (int) $mapper['away_id']], $away);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Console\Commands\DbMapper\Store;
use App\Models\CompetitionGroupProvider;
class StoreGroup
{
public static function store(&$mapper)
{
$group = [];
$group['sport_id'] = $mapper['sport_id'];
$group['competition_group_id'] = $mapper['txodds_group_id'];
$group['provider_id'] = $mapper['provider_id'];
$home['add_by_method_id'] = 3;
$group['name'] = $mapper['group'];
CompetitionGroupProvider::updateOrCreate(['provider_group_id' => (int) $mapper['group_id']], $group);
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Console\Commands;
use App\Traits\Sofascore\GrappingSofascore;
use Illuminate\Console\Command;
class Grapper extends Command
{
use GrappingSofascore;
protected $signature = 'grp:sofa {--d} {--r} {--f}';
protected $description = 'grap sofascore selecting';
public function handleGrapper(): void
{
$this->runGrapper();
}
}
+232
View File
@@ -0,0 +1,232 @@
<?php
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Fixtures\FindFixture;
use App\Console\Commands\Nuh;
use App\Models\Odds3way;
use App\Models\OddsDc;
use App\Models\OddsGgng;
use App\Models\OddsTotal;
use App\Utilities\Margin;
use App\Utilities\Notice;
use Illuminate\Support\Facades\DB;
class Betica
{
public static function switch()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note(Nuh::$options['provider'], 'g');
}
/**
* periods
* -1 Today
* -2 Next 48hrs
* 1 Tomorrow
* 2 Saturday
* 3 Sunday
* 4 Monday
* 5 Tuesday
* 6 Wednesday
* 7 Thursday
* 8 Next Week
* 9 All
*/
/**
* sort_options
* 1 Highlights
* 2 Start time
* 3 Top leagues
*/
/**
* with limit
* https://api.betika.com/v1/uo/matches?page=1&limit=10&tab=&sub_type_id=1,10,18,29&sport_id=14&tag_id=&sort_id=1&period_id=-1&esports=false
*
* ohne limit comes 100,
* https://api.betika.com/v1/uo/matches?page=1&tab=&sub_type_id=1,10,18,29&sport_id=14&tag_id=&sort_id=1&period_id=9&esports=false
*
* in meta tag are the totals
* "meta": {"total": "1053",
*
* loop max 100
*/
/**
* bettypes
* 1 => 1X2
* 10 => DOUBLE CHANCE
* 18 => TOTAL
* 19 => BOTH TEAMS TO SCORE (GG/NG)
* sub_type_id=1,10,18,29
*/
/**
* TOR exit nodes
* TANZANIA, UNITED REPUBLIC OF {tz}
* KENYA {ke}
* UGANDA {ug}
* SOMALIA ? {so}
* ETHIOPIA {et}
*
* ExitNodes {ke},{tz},{ug},{et}
* vi /etc/tor/torrc
*/
for ($page = 1; $page < 20; $page++) {
$url = "https://api.betika.com/v1/uo/matches?page=$page&limit=100&sub_type_id=1,10,18,29&sport_id=14&sort_id=2&period_id=9&esports=false";
$data = Curl::load($url);
if (! is_array($data['data']) or \count($data['data']) == 0) {
if ($debug) {
Notice::note('NO DATA', 'r');
}
return;
} else {
$total = $data['meta']['total'];
if ($debug) {
Notice::note('Total: '.$total, 'b');
}
foreach ($data['data'] as $row) {
if (isset($row['parent_match_id']) && ! $row['is_esport']) {
$event = [
'event_id' => (int) $row['match_id'],
'betradar_id' => (int) $row['parent_match_id'] ?? 0,
'sport_id' => (int) Nuh::$options['sport_id'],
'provider_id' => (int) Nuh::$options['provider_id'],
'starttime' => (string) $row['start_time'],
'country' => $row['category'] ?? 0,
'home' => $row['home_team'] ?? '',
'away' => $row['away_team'] ?? '',
'group' => $row['competition_name'] ?? '',
'group_id' => (int) $row['competition_id'] ?? 0,
];
FindFixture::find($event);
if (isset($event['id'])) {
$base = [];
$base['sport_id'] = (int) Nuh::$options['sport_id'];
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = (int) $row['match_id'];
$base['flag'] = 1;
foreach ($row['odds'] as $bettypes) {
switch ($bettypes['sub_type_id']) {
case 1:
// 1x2
$odds = [];
foreach ($bettypes['odds'] as $bettype) {
if ($bettype['outcome_id'] == 1) {
$odds['h3w'] = $bettype['odd_value'];
} elseif ($bettype['outcome_id'] == 2) {
$odds['d3w'] = $bettype['odd_value'];
} elseif ($bettype['outcome_id'] == 3) {
$odds['a3w'] = $bettype['odd_value'];
}
}
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['starttime'] = (string) $row['start_time'];
DB::transaction(function () use ($base, $event, $odds) {
Odds3way::updateOrCreate([
'event_id' => $event['id'],
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], $base + $odds);
}, 5);
break;
case 10:
// DOUBLE CHANCE
$odds = [];
foreach ($bettypes['odds'] as $bettype) {
if ($bettype['outcome_id'] == 9) {
$odds['dc1x'] = $bettype['odd_value'];
} elseif ($bettype['outcome_id'] == 10) {
$odds['dc12'] = $bettype['odd_value'];
} elseif ($bettype['outcome_id'] == 11) {
$odds['dcx2'] = $bettype['odd_value'];
}
}
$odds['margin'] = (float) Margin::calculate($odds, 1);
DB::transaction(function () use ($base, $event, $odds) {
OddsDc::updateOrCreate([
'event_id' => $event['id'],
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], $base + $odds);
}, 5);
break;
case 18:
// TOTALS
$odds = [];
foreach ($bettypes['odds'] as $bettype) {
if ($bettype['outcome_id'] == 12 && $bettype['odd_key'] == 'over 2.5') {
$odds['over'] = $bettype['odd_value'];
} elseif ($bettype['outcome_id'] == 13 && $bettype['odd_key'] == 'over 2.5') {
$odds['under'] = $bettype['odd_value'];
}
}
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['total'] = 2.5;
DB::transaction(function () use ($base, $event, $odds) {
OddsTotal::updateOrCreate([
'event_id' => $event['id'],
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], $base + $odds);
}, 5);
break;
case 29:
// BOTH TEAMS TO SCORE (GG/NG)
$odds = [];
foreach ($bettypes['odds'] as $bettype) {
if ($bettype['outcome_id'] == 74) {
$odds['gg'] = $bettype['odd_value'];
} elseif ($bettype['outcome_id'] == 76) {
$odds['ng'] = $bettype['odd_value'];
}
}
$odds['margin'] = (float) Margin::calculate($odds, 1);
DB::transaction(function () use ($base, $event, $odds) {
OddsGgng::updateOrCreate([
'event_id' => $event['id'],
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], $base + $odds);
}, 5);
default:
dd($bettypes);
break;
}
}
}
}
}
usleep(rand(10000, 20000));
}
}
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\Betsapi\Bet365;
use App\Console\Commands\Grapper\Betsapi\Bwin;
use App\Console\Commands\Grapper\Betsapi\ElementIcons;
use App\Console\Commands\Grapper\Betsapi\Fixtures;
use App\Console\Commands\Grapper\Betsapi\Odds;
use App\Console\Commands\Grapper\Betsapi\Willhill;
use App\Console\Commands\Nuh;
use App\Utilities\Notice;
class Betsapi
{
public static function switch()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note(Nuh::$options['provider'].' '.Nuh::$options['name'], 'b');
}
switch (Nuh::$options['name']) {
case 'Fixtures':
Fixtures::grap();
break;
case 'Odds':
Odds::grap();
break;
case 'Willhill':
Willhill::grap();
break;
case 'Bwin':
Bwin::grap();
break;
case 'Bet365':
Bet365::grap();
break;
case 'Element Icons':
ElementIcons::grap();
break;
default:
Notice::note('prosses name does not exist', 'r', 1);
break;
}
}
}
@@ -0,0 +1,388 @@
<?php
namespace App\Console\Commands\Grapper\Betsapi;
use App\Console\Commands\Curl;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\Odds2way;
use App\Models\Odds3way;
use App\Models\Odds3wayHt;
use App\Models\OddsDc;
use App\Models\OddsDnb;
use App\Models\OddsGgng;
use App\Models\OddsTotal;
use App\Utilities\Margin;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class Bet365
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$today = Nuh::$options['t'] ?? 0;
$week = Nuh::$options['w'] ?? 0;
$single = Nuh::$options['id'] ?? 0;
switch (Nuh::$options['sport']) {
case 'Soccer':
$sport_id = 1;
break;
case 'Ice Hockey':
$sport_id = 2;
break;
case 'Basketball':
$sport_id = 3;
break;
case 'Tennis':
$sport_id = 5;
break;
default:
Notice::note('SPORT NOT IMPLEMENTED', 'r', 1);
break;
}
$events_collector = [];
$has_markets_collector = [];
/**
* Bet365
*/
$bookmaker_id = 126;
if ($single) {
$events = Event::where('id', Nuh::$options['id'])->where('bet365_id', '>', 0)->select('id', 'sport_id', 'bet365_id', 'starttime')->get();
} elseif ($today) {
$events = Event::where('sport_id', $sport_id)->where('bet365_id', '>', 0)->where('starttime', '>=', Carbon::now())->where('starttime', '<', Carbon::now()->addDay())->select('id', 'sport_id', 'bet365_id', 'starttime')->get();
} elseif ($week) {
$events = Event::where('sport_id', $sport_id)->where('bet365_id', '>', 0)->where('starttime', '>=', Carbon::now())->where('starttime', '<', Carbon::now()->addDays(7))->select('id', 'sport_id', 'bet365_id', 'starttime')->get();
} else {
// all
$events = Event::where('sport_id', $sport_id)->where('bet365_id', '>', 0)->where('starttime', '>=', Carbon::now())->select('id', 'sport_id', 'bet365_id', 'starttime')->get();
}
if ($events ?? null && $debug) {
Notice::note('No events', 'r');
}
foreach ($events as $key => $event) {
if (! $event->has_markets) {
$has_markets_collector[] = $event->id;
}
if ($debug) {
Notice::note([
'id' => $event->id,
'bet365_id' => $event->bet365_id,
'starttime' => $event->starttime,
'count' => count($events).'/'.$key + 1,
], 'b');
}
/**
* BET365 ODDS (per event)
*/
$url = 'https://api.b365api.com/v4/bet365/prematch?token='.config('env.betsapi_token').'&FI='.$event->bet365_id;
$data = Curl::load($url);
if (isset($data['results'][0]['main'])) {
DB::transaction(function () use ($event, $bookmaker_id) {
EventBookmaker::updateOrCreate([
'event_id' => $event->id,
'sport_id' => $event->sport_id,
'bookmaker_id' => $bookmaker_id,
], ['starttime' => $event->starttime, 'in_feed' => 1, 'bmoid' => $event->bet365_id]);
}, 5);
$offer = $data['results'][0]['main']['sp'];
$base = [];
$base['event_id'] = $event->id;
$base['bookmaker_id'] = $bookmaker_id;
$base['sport_id'] = $event->sport_id;
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event->bet365_id;
$base['flags'] = 1;
/**
* ML
*/
if (isset($offer['to_win_match'])) {
$data = $offer['to_win_match']['odds'] ?? [];
if ($data) {
$odds = [];
$odds['h2w'] = number_format($data[0]['odds'], 2) ?? 1;
$odds['a2w'] = number_format($data[1]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$events_collector['odds_2ways'][] = $event->id;
$res = Odds2way::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
Odds2way::create($odds);
} else {
$res->h2w = $odds['h2w'];
$res->a2w = $odds['a2w'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
/**
* 1X2
*/
if (isset($offer['full_time_result'])) {
$data = $offer['full_time_result']['odds'] ?? [];
if ($data) {
$odds = [];
$odds['h3w'] = number_format($data[0]['odds'], 2) ?? 1;
$odds['d3w'] = number_format($data[1]['odds'], 2) ?? 1;
$odds['a3w'] = number_format($data[2]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$events_collector['odds_3ways'][] = $event->id;
$res = Odds3way::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
Odds3way::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->a3w = $odds['d3w'];
$res->d3w = $odds['a3w'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
/**
* DC
*/
if (isset($offer['double_chance'])) {
$data = $offer['double_chance']['odds'] ?? [];
if ($data) {
$odds = [];
$odds['dc1x'] = number_format($data[0]['odds'], 2) ?? 1;
$odds['dc12'] = number_format($data[1]['odds'], 2) ?? 1;
$odds['dcx2'] = number_format($data[2]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$events_collector['odds_dc'][] = $event->id;
$res = OddsDc::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
OddsDc::create($odds);
} else {
$res->dc1x = $odds['dc1x'];
$res->dc12 = $odds['dc12'];
$res->dcx2 = $odds['dcx2'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
/**
* OU
*/
if (isset($offer['goals_over_under'])) {
$data = $offer['goals_over_under']['odds'] ?? [];
if ($data) {
$odds = [];
$odds['over'] = number_format($data[0]['odds'], 2) ?? 1;
$odds['under'] = number_format($data[1]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
if ($base['sport_id'] == 1) {
$odds['active_spread'] = 1;
}
$odds = array_merge($odds, $base);
$events_collector['odds_totals'][] = $event->id;
if ($offer['goals_over_under']['odds'][1]['name'] == '2.5') {
$odds['total'] = 2.5;
$res = OddsTotal::where('event_id', $event->id)
->where('bookmaker_id', $bookmaker_id)
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotal::create($odds);
} else {
$res->over = $odds['over'];
$res->under = $odds['under'];
$res->difference = abs(1 / $odds['over'] - 1 / $odds['under']);
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
/**
* GG NG
*/
if (isset($offer['both_teams_to_score'])) {
$data = $offer['both_teams_to_score']['odds'] ?? [];
if ($data) {
$odds = [];
$odds['gg'] = number_format($data[0]['odds'], 2) ?? 1;
$odds['ng'] = number_format($data[1]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$events_collector['odds_ggng'][] = $event->id;
$res = OddsGgng::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
OddsGgng::create($odds);
} else {
$res->gg = $odds['gg'];
$res->ng = $odds['ng'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
/**
* DNB
*/
if (isset($offer['draw_no_bet'])) {
$data = $offer['draw_no_bet']['odds'] ?? [];
if ($data) {
$odds = [];
$odds['dnb1'] = number_format($data[0]['odds'], 2) ?? 1;
$odds['dnb2'] = number_format($data[1]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$res = OddsDnb::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
$odds = array_merge($odds, $base);
$events_collector['odds_dnb'][] = $event->id;
if (! $res) {
OddsDnb::create($odds);
} else {
$res->dnb1 = $odds['dnb1'];
$res->dnb2 = $odds['dnb2'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
/**
* 1X2 HT
*/
if (isset($offer['half_time_result'])) {
$data = $offer['half_time_result']['odds'] ?? [];
if ($data) {
$odds = [];
$odds['h3w'] = number_format($data[0]['odds'], 2) ?? 1;
$odds['d3w'] = number_format($data[1]['odds'], 2) ?? 1;
$odds['a3w'] = number_format($data[2]['odds'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$events_collector['odds_3ways_ht'][] = $event->id;
$res = Odds3wayHt::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
Odds3wayHt::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->d3w = $odds['d3w'];
$res->a3w = $odds['a3w'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
}
$id_collector = [];
foreach ($events_collector as $table => $event_ids) {
$id_collector[] = $event_ids;
DB::table($table)->where('bookmaker_id', $bookmaker_id)->whereNotIn('event_id', $event_ids)->update(['flags' => 0]);
}
if ($id_collector) {
foreach ($id_collector as $event_id) {
if (in_array($event_id, $has_markets_collector)) {
Event::where('id', $event_id)->update(['has_markets' => 1]);
}
}
}
}
}
@@ -0,0 +1,74 @@
<?php
namespace App\Console\Commands\Grapper\Betsapi;
use App\Console\Commands\Curl;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Models\Sport;
use App\Utilities\Notice;
class Bwin
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$sportmap = Sport::map('bwin');
foreach ($sportmap as $bwin_sport_id) {
$page = 1;
$total = 10;
/**
* BWIN ODDS & BETRADAR ID (per page)
* only get BETRADAR ID no storing of data
*/
$base_url = 'https://api.b365api.com/v1/bwin/prematch?token='.config('env.betsapi_token').'&skip_markets=1&page=###page###&sport_id='.$bwin_sport_id;
while ($page <= $total) {
if ($debug) {
Notice::note("Page: $page \Sport: $bwin_sport_id", 'b');
}
$url = str_replace('###page###', $page, $base_url);
$data = Curl::load($url);
if (isset($data['pager'])) {
$total = round($data['pager']['total'] / $data['pager']['per_page']);
}
$page++;
if (isset($data['results'])) {
foreach ($data['results'] as $event) {
if ($debug && isset($event['HomeTeam']) && isset($event['SportName'])) {
Notice::note($event['RegionName'].'-'.$event['SportName']."\n".$event['HomeTeam'].' - '.$event['AwayTeam']);
}
$betsapi_id = $event['our_event_id'] ?? 0;
$betradar_id = $event['BetRadarId'] ?? 0;
$bwin_id = $event['Id'] ?? 0;
if ($betradar_id && $betsapi_id) {
if ($debug) {
Notice::note(["Betsapi ID : $betsapi_id", "Betradar ID : $betradar_id", "Bwin ID : $bwin_id"]);
}
Event::where('betsapi_id', (int) $betsapi_id)->update(['betradar_id' => $betradar_id, 'bwin_id' => $bwin_id]);
Mapper::where('betradar_id', $betradar_id)->delete();
}
}
}
}
}
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Console\Commands\Grapper\Betsapi;
use App\Console\Commands\Curl;
use App\Console\Commands\Nuh;
use App\Models\Element;
use App\Models\ElementProvider;
use App\Utilities\Notice;
class ElementIcons
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$min_id = 1;
while ($min_id > 0) {
if ($min_id == 1) {
$url = 'https://api.b365api.com/v3/team?token='.config('env.betsapi_token').'&sport_id=1&is_esports=1';
} else {
$url = 'https://api.b365api.com/v3/team?token='.config('env.betsapi_token').'&sport_id=1&is_esports=1&max_id='.$min_id;
}
$data = Curl::load($url);
if (! $data['success']) {
break;
}
$min_id = $data['pager']['min_id'];
if ($debug) {
Notice::note("MinId: $min_id");
}
foreach ($data['results'] as $value) {
if (! isset($value['is_esports']) && $value['image_id'] > 0 && $value['cc'] != '') {
$res = ElementProvider::where('provider_id', 2)->where('provider_element_id', (int) $value['id'])->first();
if ($res) {
if ($debug) {
Notice::note($value, 'b');
}
Element::where('id', $res->element_id)->update(['betsapi_image_id' => $value['image_id']]);
}
}
}
}
}
}
@@ -0,0 +1,112 @@
<?php
namespace App\Console\Commands\Grapper\Betsapi;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Fixtures\FindFixture;
use App\Console\Commands\Nuh;
use App\Models\Country;
use App\Models\Mapper;
use App\Models\Sport;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Fixtures
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$today = Nuh::$options['t'] ?? 0;
FindFixture::start();
/**
* Delete Started
*/
$info = Mapper::where('starttime', '<', Carbon::now()->subHours(2))->delete();
if ($debug) {
Notice::note("Deleted: $info");
}
$country_map = Country::pluck('id', 'iso2');
$sportmap = Sport::map('bapi', 0, [1, 2, 3, 5]);
$now = Carbon::now();
for ($i = 0; $i < 30; $i++) {
if ($debug) {
Notice::note('Day: '.$now->format('d. M Y'), 'g');
}
$base_url = 'https://api.b365api.com/v3/events/upcoming?sport_id=###sport_id###&page=###page###&day='.$now->format('Ymd').'&skip_esports=1&token='.config('env.betsapi_token');
$now->addDays(1);
$total = 1;
foreach ($sportmap as $sport_id => $betsapi_sport_id) {
$sport_url = str_replace('###sport_id###', $betsapi_sport_id, $base_url);
$page = 1;
while ($page <= $total) {
$url = str_replace('###page###', $page, $sport_url);
$data = Curl::load($url);
if (! isset($data['pager'])) {
return;
}
$page++;
if (isset($data['pager']['total'])) {
$total = round($data['pager']['total'] / $data['pager']['per_page']);
if ($debug) {
Notice::note("Page: $page \nTotal: $total");
}
if (isset($data['results']) && \count($data['results'])) {
foreach ($data['results'] as $row) {
if (isset($row['home']['id']) && isset($row['away']['id']) && strpos($row['league']['name'], 'Esoccer') === false) {
$cc = strtoupper($row['league']['cc']);
$event = [
'event_id' => (int) $row['id'],
'bet365_id' => isset($row['bet365_id']) ? $row['bet365_id'] : 0,
'sport_id' => (int) $sport_id,
'provider_id' => (int) Nuh::$options['provider_id'],
'starttime' => Carbon::createFromTimestamp((string) $row['time'])->toDateTimeString(),
'country_id' => $country_map[$cc] ?? 0,
'home' => $row['home']['name'] ?? '',
'home_id' => (int) $row['home']['id'],
'home_cc' => strtoupper($row['home']['cc']) ?? '',
'away' => $row['away']['name'] ?? '',
'away_id' => (int) $row['away']['id'],
'away_cc' => strtoupper($row['away']['cc']) ?? '',
'group' => $row['league']['name'] ?? '',
'group_id' => (int) $row['league']['id'] ?? 0,
'group_cc' => strtoupper($row['league']['cc']) ?? '',
];
FindFixture::find($event);
}
}
}
}
}
}
if ($today) {
break;
}
}
}
}
@@ -0,0 +1,148 @@
<?php
namespace App\Console\Commands\Grapper\Betsapi;
use App\Console\Commands\Curl;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Odds3way;
use App\Models\Supervisor;
use App\Utilities\Margin;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class Odds
{
/**
* Create a new class instance.
*/
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$today = Nuh::$options['t'] ?? 0;
$week = Nuh::$options['w'] ?? 0;
$single = Nuh::$options['id'] ?? 0;
if ($debug) {
Notice::note('BETSAPI ODDS '.Nuh::$options['sport'], 'b');
}
$sources = [83 => 'pinnaclesports'];
$flags = [];
if ($single) {
$events = Event::where('id', Nuh::$options['id'])->where('betsapi_id', '>', 0)->select('id', 'sport_id', 'bet365_id', 'betsapi_id', 'starttime')->get();
} elseif ($today) {
$events = Event::where('sport_id', Nuh::$options['sport_id'])->where('betsapi_id', '>', 0)->where('starttime', '>=', Carbon::now())->where('starttime', '<', Carbon::now()->addDay())->select('id', 'sport_id', 'bet365_id', 'betsapi_id', 'starttime')->get();
} elseif ($week) {
$events = Event::where('sport_id', Nuh::$options['sport_id'])->where('betsapi_id', '>', 0)->where('starttime', '>=', Carbon::now())->where('starttime', '<', Carbon::now()->addDays(7))->select('id', 'sport_id', 'bet365_id', 'betsapi_id', 'starttime')->get();
} else {
// all
$events = Event::where('sport_id', Nuh::$options['sport_id'])->where('betsapi_id', '>', 0)->where('starttime', '>=', Carbon::now())->select('id', 'sport_id', 'bet365_id', 'betsapi_id', 'starttime')->get();
}
foreach ($events as $key => $event) {
if ($debug) {
Notice::note([
'id' => $event->id,
'betsapi_id' => $event->betsapi_id,
'starttime' => $event->starttime,
'count' => count($events).'/'.$key + 1,
], 'b');
}
$since_time = Nuh::$options['lastcall'] - 600;
$since_time = 0;
foreach ($sources as $bookmaker_id => $source) {
$url = 'https://api.b365api.com/v2/event/odds?token='.config('env.betsapi_token').'&source'.$source.'&since_time='.$since_time.'&event_id='.$event->betsapi_id;
$data = Curl::load($url);
$base = [];
$base['event_id'] = $event->id;
$base['bookmaker_id'] = $bookmaker_id;
$base['sport_id'] = $event->sport_id;
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event->betsapi_id;
$base['flag'] = 1;
foreach ($data['results']['odds'] as $key => $value) {
switch ($key) {
case '1_1':
$odds = [];
$odds['h3w'] = number_format($value[0]['home_od'], 2) ?? 1;
$odds['d3w'] = number_format($value[0]['draw_od'], 2) ?? 1;
$odds['a3w'] = number_format($value[0]['away_od'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$flags['odds_3ways'][] = $event->id;
$res = Odds3way::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
Odds3way::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->d3w = $odds['d3w'];
$res->a3w = $odds['a3w'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
break;
case '1_3':
// dd($value);
$odds = [];
$odds['h3w'] = number_format($value[0]['home_od'], 2) ?? 1;
$odds['d3w'] = number_format($value[0]['draw_od'], 2) ?? 1;
$odds['a3w'] = number_format($value[0]['away_od'], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$res = Odds3way::where('event_id', $event->id)->where('bookmaker_id', $bookmaker_id)->first();
if (! $res) {
Odds3way::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->d3w = $odds['d3w'];
$res->a3w = $odds['a3w'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
break;
}
}
}
Supervisor::where('id', Nuh::$options['supervisor_id'])->update(['lastcall' => time()]);
}
// needs check
foreach ($flags as $table => $event_ids) {
DB::table($table)->where('bookmaker_id', $bookmaker_id)->whereNotIn('event_id', $event_ids)->update(['flags' => 0]);
}
}
}
@@ -0,0 +1,111 @@
<?php
namespace App\Console\Commands\Grapper\Betsapi;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Fixtures\StoreElement;
use App\Console\Commands\Grapper\Fixtures\StoreGroup;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\Mapper;
use App\Models\Odds2way;
use App\Models\Odds3way;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Willhill
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
/**
* williamhill
*/
$bookmaker_id = 42;
$collection = [];
$res = Odds3way::with('event')->where('bookmaker_id', $bookmaker_id)->get();
foreach ($res as $value) {
if ($value->event->starttime > Carbon::now() && $value->event->starttime < Carbon::now()->addDays(7) && $value->event->betsapi_id == 0) {
$collection[] = [
'txodds_id' => $value->event_id,
'willhill_id' => $value->bmoid,
'sport_id' => $value->sport_id,
];
}
}
$res = Odds2way::with('event')->where('bookmaker_id', $bookmaker_id)->get();
foreach ($res as $value) {
if ($value->event->starttime > Carbon::now() && $value->event->starttime < Carbon::now()->addDays(7) && $value->event->betsapi_id == 0) {
$collection[] = [
'txodds_id' => $value->event_id,
'willhill_id' => $value->bmoid,
'sport_id' => $value->sport_id,
];
}
}
foreach ($collection as $event) {
$url = 'https://api.b365api.com/v1/williamhill/result?token='.config('env.betsapi_token').'&event_id='.$event['willhill_id'];
$data = Curl::load($url);
$betsapi_id = $data['results'][0]['id'] ?? 0;
$bet365_id = $data['results'][0]['bet365_id'] ?? 0;
if ($debug) {
$arr = [
'Mapper TXOdds to Bet365',
'TXdds ID : '.$event['txodds_id'],
"Bet365 ID : $bet365_id",
'Willhill ID : '.$event['willhill_id'],
'Sport ID : '.$event['sport_id'],
];
Notice::note($arr, 'b');
}
if ($betsapi_id) {
if (isset($data['results'][0]['home'])) {
$match = Event::where('id', (int) $event['txodds_id'])->first();
$ele = [];
$ele['sport_id'] = $event['sport_id'];
$ele['provider_id'] = Nuh::$options['provider_id'];
$ele['element_id'] = $match->home_id ?? 0;
$ele['provider_element_id'] = $data['results'][0]['home']['id'] ?? 0;
$ele['name'] = $data['results'][0]['home']['name'];
StoreElement::store($elements, $ele);
$ele = [];
$ele['sport_id'] = $event['sport_id'];
$ele['provider_id'] = Nuh::$options['provider_id'];
$ele['element_id'] = $match->away_id ?? 0;
$ele['provider_element_id'] = $data['results'][0]['away']['id'] ?? 0;
$ele['name'] = $data['results'][0]['away']['name'];
StoreElement::store($elements, $ele);
$group = [];
$ele['sport_id'] = $event['sport_id'];
$group['provider_id'] = Nuh::$options['provider_id'];
$group['competition_group_id'] = $match->competition_group_id;
$group['provider_group_id'] = $data['results'][0]['league']['id'] ?? 0;
$group['name'] = $data['results'][0]['league']['name'];
StoreGroup::store($groups, $group);
$match->betsapi_id = $betsapi_id;
$match->bet365_id = $bet365_id;
$match->save();
if ($betsapi_id) {
Mapper::where('event_id', $betsapi_id)->delete();
}
}
}
}
}
}
@@ -0,0 +1,196 @@
<?php
namespace App\Console\Commands\Grapper\Fixtures;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\Mapper;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class FindFixture
{
public static $elements = [];
public static $groups = [];
/***
"event_id" => 3864842
"betradar_id" => 62924779
"sport_id" => 3
"provider_id" => 3
"country_id" => 128
"country" => "USA"
"group_id" => 1301
"group" => "NBA"
"starttime" => "2026-02-22 20:30:00"
"home_id" => 6855
"home" => "Golden State Warriors"
"away_id" => 6843
"away" => "Denver Nuggets"
*/
public static function start()
{
self::$elements = LoadElements::load(Nuh::$options['provider_id'], true);
self::$groups = LoadGroups::load(Nuh::$options['provider_id'], true);
}
public static function find(&$event)
{
$event_id = $event['event_id'];
$betradar_id = $event['betradar_id'] ?? 0;
$betsapi_id = $event['betsapi_id'] ?? 0;
$bet365_id = $event['bet365_id'] ?? 0;
$_1xbet_id = $event['_1xbet_id'] ?? 0;
$bwin_id = $event['bwin_id'] ?? 0;
/*************************************************
* USE ID
*************************************************/
// DEFAULT BETRADAR
if ($betradar_id) {
$match = Event::where('betradar_id', $betradar_id)->first();
}
if (! isset($match) or ! $match) {
switch ($event['provider_id']) {
case 2:
// BETSAPI
$match = Event::where('betsapi_id', '=', $event_id)->first();
break;
case 3:
// MAGLOO KENIA
$res = EventBookmaker::where('bookmaker_id', 10)->where('event_id', $event_id)->first();
if ($res) {
$match = Event::where('id', $res->event_id)->first();
}
break;
case 4:
// MAGLOO NIGERIA
$res = EventBookmaker::where('bookmaker_id', 16)->where('event_id', $event_id)->first();
if ($res) {
$match = Event::where('id', $res->event_id)->first();
}
break;
case 5:
// LOGIFUTUR NIGERA
$res = EventBookmaker::where('bookmaker_id', 35)->where('event_id', $event_id)->first();
if ($res) {
$match = Event::where('id', $res->event_id)->first();
}
break;
case 6:
// LOGIFUTUR COLOMBIA
$res = EventBookmaker::where('bookmaker_id', 36)->where('event_id', $event_id)->first();
if ($res) {
$match = Event::where('id', $res->event_id)->first();
}
break;
}
}
if (isset($match)) {
$update_array = [];
if ($betradar_id && ! $match->betradar_id) {
$update_array['betradar_id'] = $betradar_id;
}
if ($betsapi_id && ! $match->betsapi_id) {
$update_array['betsapi_id'] = $betsapi_id;
}
if ($bet365_id && ! $match->bet365_id) {
$update_array['bet365_id'] = $bet365_id;
}
if ($_1xbet_id && ! $match->_1xbet_id) {
$update_array['bet365_id'] = $_1xbet_id;
}
if ($bwin_id && ! $match->bwin_id) {
$update_array['bwin_id'] = $bwin_id;
}
if ($update_array) {
DB::transaction(function () use ($match, $update_array) {
Event::where('id', $match->id)->update($update_array);
}, 5);
}
if (! in_array(Nuh::$options['provider_id'], [5, 6, 9])) {
StoreData::store($event, $match);
}
Mapper::where('event_id', $event_id)->delete();
$event['id'] = $match->id;
return;
}
if (in_array(Nuh::$options['provider_id'], [3, 4, 5, 6, 9, 10])) {
Mapper::updateOrCreate(['event_id' => $event_id], $event);
}
/*************************************************
* FIND
*************************************************/
if (isset($event['home_id']) && isset($event['away_id']) && isset($event['group_id'])) {
$starttime = $event['starttime'];
$from = Carbon::createFromDate($starttime)->subDay();
$to = Carbon::createFromDate($starttime)->addDay();
$home_id = FindFixture::$elements[$event['home_id']] ?? 0;
$away_id = FindFixture::$elements[$event['away_id']] ?? 0;
$competition_group_id = FindFixture::$groups[$event['group_id']] ?? 0;
if ($home_id && $away_id && $competition_group_id) {
$match_id = Event::query()
->where('home_id', $home_id)
->where('away_id', $away_id)
->where('competition_group_id', $competition_group_id)
->where('starttime', '>', $from)
->where('starttime', '<', $to)
->value('id');
if ($match_id) {
$event['id'] = $match_id;
$update_array = [];
if ($betradar_id) {
$update_array['betradar_id'] = $betradar_id;
}
if ($betsapi_id) {
$update_array['betsapi_id'] = $betsapi_id;
}
if ($bet365_id) {
$update_array['bet365_id'] = $bet365_id;
}
if ($update_array) {
Event::where('id', $match_id)->update($update_array);
}
} else {
Mapper::updateOrCreate(['event_id' => $event_id], $event);
}
} else {
Mapper::updateOrCreate(['event_id' => $event_id], $event);
}
}
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Console\Commands\Grapper\Fixtures;
use App\Models\ElementProvider;
class LoadElements
{
public static function load($provider_id, $load_by_name = false)
{
$res = ElementProvider::where('provider_id', $provider_id)->get();
$r = [];
foreach ($res as $val) {
if ($load_by_name) {
$r[$val->sport_id][$val->name] = $val->element_id;
} else {
$r[$val->sport_id][$val->provider_element_id] = $val->element_id;
}
}
return $r;
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Console\Commands\Grapper\Fixtures;
use App\Models\CompetitionGroupProvider;
class LoadGroups
{
public static function load($provider_id, $load_by_name = false)
{
$res = CompetitionGroupProvider::where('provider_id', $provider_id)->get();
$r = [];
foreach ($res as $val) {
if ($load_by_name) {
$r[$val->sport_id][$val->name] = $val->competition_group_id;
} else {
$r[$val->sport_id][$val->provider_group_id] = $val->competition_group_id;
}
}
return $r;
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands\Grapper\Fixtures;
use App\Models\CompetitionGroupProvider;
use App\Models\ElementProvider;
class StoreData
{
public static function store(&$event, &$match)
{
$home_id = FindFixture::$elements[$event['home_id']] ?? 0;
$away_id = FindFixture::$elements[$event['away_id']] ?? 0;
$competition_group_id = FindFixture::$groups[$event['group_id']] ?? 0;
if (! $home_id) {
$ele = [];
$ele['sport_id'] = $event['sport_id'];
$ele['provider_id'] = $event['provider_id'];
$ele['element_id'] = $match->home_id ?? 0;
$home['add_by_method_id'] = 1;
$ele['name'] = $event['home'];
ElementProvider::updateOrCreate(['provider_element_id' => (int) $event['home_id']], $ele);
}
if (! $away_id) {
$ele = [];
$ele['sport_id'] = $event['sport_id'];
$ele['provider_id'] = $event['provider_id'];
$ele['element_id'] = $match->away_id ?? 0;
$home['add_by_method_id'] = 1;
$ele['name'] = $event['away'];
ElementProvider::updateOrCreate(['provider_element_id' => (int) $event['away_id']], $ele);
}
if (! $competition_group_id) {
$group = [];
$group['sport_id'] = $event['sport_id'];
$group['provider_id'] = $event['provider_id'];
$group['competition_group_id'] = $match->competition_group_id;
$home['add_by_method_id'] = 1;
$group['name'] = $event['group'];
CompetitionGroupProvider::updateOrCreate(['provider_group_id' => (int) $event['group_id']], $group);
}
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Console\Commands\Grapper\Fixtures;
use App\Models\ElementProvider;
class StoreElement
{
public static function store(&$elements, $ele)
{
$provider_element_id = $ele['provider_element_id'] ?? 0;
unset($ele['provider_element_id']);
$ele['add_by_method_id'] = 1;
$sport_id = $ele['sport_id'] ?? 0;
if ($sport_id && ! isset($elements[$sport_id][$provider_element_id])) {
ElementProvider::updateOrCreate(['provider_element_id' => (int) $provider_element_id], $ele);
}
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Console\Commands\Grapper\Fixtures;
use App\Models\CompetitionGroupProvider;
class StoreGroup
{
public static function store(&$groups, $group)
{
$provider_group_id = $group['provider_group_id'] ?? 0;
unset($group['provider_group_id']);
$sport_id = $group['sport_id'] ?? 0;
$ele['add_by_method_id'] = 1;
if ($sport_id && ! isset($groups[$sport_id][$provider_group_id])) {
CompetitionGroupProvider::updateOrCreate(['provider_group_id' => (int) $provider_group_id], $group);
}
}
}
+147
View File
@@ -0,0 +1,147 @@
<?php
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\Fixtures\FindFixture;
use App\Console\Commands\Nuh;
use App\Models\Odds3way;
use App\Models\OddsDc;
use App\Models\OddsGgng;
use App\Models\OddsTotal;
use App\Utilities\Margin;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class Goldbet
{
public static function switch()
{
$debug = Nuh::$options['d'] ?? 0;
$save = Nuh::$options['s'] ?? 0;
$read = Nuh::$options['r'] ?? 0;
$filename = app_path().'/Console/Commands/TestFiles/goldbet.json';
if ($debug) {
Notice::note(Nuh::$options['provider'], 'g');
}
if ($read) {
if ($debug) {
Notice::note('data read localy', 'g');
}
$file = file_get_contents($filename);
$data = json_decode($file, true);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://gb.nuhodds.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Proxy-Auth: jjW2jVVezcMURUBuhzf6VDXXsMhN5JWKEeQ5pYusg7b29G',
'Proxy-Target-URL: '.Nuh::$options['base_url'],
// 'Proxy-Debug: 1'
]);
$file = curl_exec($ch);
}
if ($save) {
file_put_contents($filename, $file);
Notice::note('file saved localy', 'g');
}
$data = json_decode($file, true);
// https://api.b365api.com/v1/sbobet/event?token=36152-aeTRNnZxSPUwGe&event_id=10399052
// https://api.b365api.com/v1/sbobet/inplay?sport_id=1&token=36152-aeTRNnZxSPUwGe
foreach ($data as $row) {
if ($row['liga'] != 'Fantasy Matches') {
/**
* sportid is same like txoods
*/
$event = [
'event_id' => (int) $row['matchid'],
'sport_id' => (int) $row['sport'],
'provider_id' => (int) Nuh::$options['provider_id'],
'starttime' => (string) Carbon::createFromTimestamp((string) $row['starttime'])->toDateTimeString(),
'country' => $row['country'] ?? 0,
'country_id' => (int) $row['countryid'] ?? 0,
'home' => $row['e1'] ?? '',
'home_id' => (int) $row['e2id'],
'away' => $row['e2'] ?? '',
'away_id' => (int) $row['e2id'],
'group' => $row['liga'] ?? '',
'group_id' => (int) $row['lid'] ?? 0,
];
FindFixture::find($event);
if (isset($event['id'])) {
$base = [];
$base['sport_id'] = (int) Nuh::$options['sport_id'];
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = (int) $row['match_id'];
$base['flag'] = 1;
if (isset($row['1x2'])) {
$odds = [];
$odds['h3w'] = $row['1x2']['one'];
$odds['d3w'] = $row['1x2']['x'];
$odds['a3w'] = $row['1x2']['two'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['starttime'] = (string) $row['start_time'];
Odds3way::updateOrCreate([
'event_id' => $event['id'],
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], $base + $odds);
}
if (isset($row['ou'])) {
$odds = [];
$odds['over'] = $row['ou']['over'];
$odds['under'] = $row['ou']['under'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['total'] = 2.5;
OddsTotal::updateOrCreate([
'event_id' => $event['id'],
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], $base + $odds);
}
if (isset($row['dc'])) {
$odds = [];
$odds['dc1x'] = $row['dc']['dc1x'];
$odds['dc12'] = $row['dc']['dc12'];
$odds['dcx2'] = $row['dc']['dcx2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['starttime'] = (string) $row['start_time'];
OddsDc::updateOrCreate([
'event_id' => $event['id'],
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], $base + $odds);
}
if (isset($row['gg_ng'])) {
$odds = [];
$odds['gg'] = $row['gg_ng']['gg'];
$odds['ng'] = $row['gg_ng']['ng'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['starttime'] = (string) $row['start_time'];
OddsGgng::updateOrCreate([
'event_id' => $event['id'],
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], $base + $odds);
}
}
}
}
}
}
+125
View File
@@ -0,0 +1,125 @@
<?php
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\Fixtures\FindFixture;
use App\Console\Commands\Grapper\Logifuture\Basketball;
use App\Console\Commands\Grapper\Logifuture\Icehockey;
use App\Console\Commands\Grapper\Logifuture\Soccer;
use App\Console\Commands\Grapper\Logifuture\Tennis;
use App\Console\Commands\Grapper\Logifuture\Tools\Authentication;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureData;
use App\Console\Commands\Grapper\Logifuture\Tools\MapEvent;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\Sport;
use App\Utilities\Notice;
use Illuminate\Support\Facades\DB;
class Logifuture
{
public static $auth_header = [];
public static $base_url = '';
public static function switch()
{
// dd(Nuh::$options);
$debug = Nuh::$options['d'] ?? 0;
$echo_data = Nuh::$options['e'] ?? 0;
$sportmap = Sport::map('logi', 1, [Nuh::$options['sport_id']]);
$event_id_collector = [];
if ($debug) {
Notice::note(Nuh::$options['provider'].' '.Nuh::$options['sport'], 'g');
}
Authentication::authenticate();
foreach ($sportmap as $logifuture_sport_id => $sport_id) {
$matches = LogifutureData::load($logifuture_sport_id);
// Notice::note($matches, 'b');
if ($echo_data) {
Notice::note($matches, 'g');
}
if (! is_array($matches)) {
return;
}
if (! isset($matches['error'])) {
foreach ($matches as $match) {
// Notice::note($match, 'r');
if (strpos($match['sportCategory'], 'Simulated Reality') === false) {
$event = MapEvent::filter($sport_id, $match);
FindFixture::find($event);
// Notice::note($event, 'r');
if (isset($event['id']) && Event::where('id', $event['id'])->exists()) {
// Notice::note($event, 'b');
$event_id_collector[] = $event['id'];
DB::transaction(function () use ($event, $sport_id) {
EventBookmaker::updateOrCreate([
'event_id' => $event['id'],
'sport_id' => $sport_id,
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], ['in_feed' => 1, 'bmoid' => $event['id'], 'starttime' => $event['starttime']]);
}, 5);
switch ($sport_id) {
case 1:
Soccer::get($event, $match);
break;
case 2:
Icehockey::get($event, $match);
break;
case 3:
Basketball::get($event, $match);
break;
case 5:
Tennis::get($event, $match);
break;
default:
Notice::note('SPORT NOT IMPLEMENTED', 'r', 1);
break;
}
}
}
}
}
}
if ($event_id_collector) {
if ($debug) {
// Notice::note($event_id_collector, 'r');
}
EventBookmaker::whereNotIn('event_id', $event_id_collector)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->update(['in_feed' => 0]);
$tables = ['odds_2ways', 'odds_2ways_s1', 'odds_3ways', 'odds_totals', 'odds_points', 'odds_ggng', 'odds_dc', 'odds_tq', 'odds_points_q1', 'odds_totals_q1'];
foreach ($tables as $table) {
DB::transaction(function () use ($table, $event_id_collector) {
DB::table($table)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->whereNotIn('event_id', $event_id_collector)->update(['flags' => 0]);
}, 5);
}
}
}
}
@@ -0,0 +1,124 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture;
use App\Console\Commands\Grapper\Logifuture\Tools\FilterHandicap;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStorePoints;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStoreTotals;
use App\Console\Commands\Nuh;
class Basketball
{
public static function get(&$event, $match)
{
$n_totals = [];
$n_totals_qt = [];
$n_points = [];
$n_points_qt = [];
$c_totals = [];
$c_totals_qt = [];
$c_points = [];
$c_points_qt = [];
foreach ($match['odds'] as $name => $value) {
/*
case 'B_1X2_1':
$event['h3w'] = $value;
break;
case 'B_1X2_X':
$event['d3w'] = $value;
break;
case 'B_1X2_2':
$event['a3w'] = $value;
break;
case 'B_12_1':
$_bai_2way['h2w'] = $value;
break;
case 'B_12_2':
$_bai_2way['a2w'] = $value;
break;
*/
if (strpos($name, '@') !== false) {
$pos = strpos($name, '@');
$market = substr($name, 0, $pos);
switch ($market) {
// NIGERIA
case 'B_OUN':
$n_totals[$name] = number_format($value, 2);
break;
case 'B_1QOU':
$n_totals_qt[$name] = number_format($value, 2);
break;
case 'B_H':
$n_points[$name] = number_format($value, 2);
break;
case 'B_1QH':
$n_points_qt[$name] = number_format($value, 2);
break;
// COLOMBIA
case 'B_OUHND':
$c_totals[$name] = number_format($value, 2);
break;
case 'B_OUHND1P':
$c_totals_qt[$name] = number_format($value, 2);
break;
case 'B_12HND':
$c_points[$name] = number_format($value, 2);
break;
case 'B_12HND1P':
$c_points_qt[$name] = number_format($value, 2);
break;
}
}
}
$_spreads = [];
// COLUMBIA
if ($c_totals) {
FilterHandicap::filter($_spreads['total'], 'B_OUHND@', $c_totals, ['over', 'under', 'total']);
}
if ($c_totals_qt) {
FilterHandicap::filter($_spreads['total_qt'], 'B_OUHND1P@', $c_totals_qt, ['over', 'under', 'total']);
}
if ($c_points) {
FilterHandicap::filter($_spreads['point'], 'B_12HND@', $c_points, ['hth1', 'hth2', 'hcap']);
}
if ($c_points_qt) {
FilterHandicap::filter($_spreads['point_qt'], 'B_12HND1P@', $c_points_qt, ['hth1', 'hth2', 'hcap']);
}
// NIGERIA
if ($n_totals) {
FilterHandicap::filter($_spreads['total'], 'B_OUN@', $n_totals, ['over', 'under', 'total']);
}
if ($n_totals_qt) {
FilterHandicap::filter($_spreads['total_qt'], 'B_1QOU@', $n_totals_qt, ['over', 'under', 'total']);
}
if ($n_points) {
FilterHandicap::filter($_spreads['point'], 'B_H@', $n_points, ['hth1', 'hth2', 'hcap']);
}
if ($n_points_qt) {
FilterHandicap::filter($_spreads['point_qt'], 'B_1QH@', $n_points_qt, ['hth1', 'hth2', 'hcap']);
}
$base = [];
$base['event_id'] = $event['id'];
$base['bookmaker_id'] = $event['bookmaker_id'];
$base['sport_id'] = $event['sport_id'];
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event['event_id'];
$base['flags'] = 1;
if (isset($_spreads['total'])) {
LogifutureStoreTotals::store($_spreads['total'], $base);
}
if (isset($_spreads['point'])) {
LogifutureStorePoints::store($_spreads['point'], $base);
}
}
}
@@ -0,0 +1,184 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture;
use App\Console\Commands\Grapper\Logifuture\Tools\FilterHandicap;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStorePoints;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStorePointsQ1;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStoreTotals;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStoreTotalsQ1;
use App\Console\Commands\Nuh;
use App\Models\Odds2way;
use App\Models\Odds2wayS1;
use App\Models\Odds3way;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class Icehockey
{
public static function get(&$event, $match)
{
$ml = [];
$mls1 = [];
$_3way = [];
$n_totals = [];
$n_points = [];
$c_totals = [];
$c_points = [];
foreach ($match['odds'] as $name => $value) {
switch ($name) {
case 'IH_1X2_1':
$_3way['h3w'] = number_format($value, 2);
break;
case 'IH_1X2_X':
$_3way['d3w'] = number_format($value, 2);
break;
case 'IH_1X2_2':
$_3way['a3w'] = number_format($value, 2);
break;
case 'IH_12_1':
$ml['h2w'] = number_format($value, 2);
break;
case 'IH_12_2':
$ml['a2w'] = number_format($value, 2);
break;
case 'IH_12OTAP_1':
$mls1['h2w'] = number_format($value, 2);
break;
case 'IH_12OTAP_2':
$mls1['a2w'] = number_format($value, 2);
break;
}
if (strpos($name, '@') !== false) {
$pos = strpos($name, '@');
$market = substr($name, 0, $pos);
switch ($market) {
// NIGERIA
case 'IH_TF':
$n_totals[$name] = $value;
break;
case 'IH_HR1':
$n_points[$name] = $value;
break;
// COLOMBIA
case 'IH_OUHND':
$c_totals[$name] = $value;
break;
case 'IH_12HND':
$c_points[$name] = $value;
break;
}
}
}
$base = [];
$base['event_id'] = $event['id'];
$base['bookmaker_id'] = $event['bookmaker_id'];
$base['sport_id'] = $event['sport_id'];
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event['event_id'];
$base['flags'] = 1;
// 1x2
if (\count($_3way) == 3) {
$_3way['margin'] = (float) Margin::calculate($_3way, 1);
$_3way = array_merge($_3way, $base);
$res = Odds3way::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds3way::create($_3way);
} else {
$res->h3w = number_format($_3way['h3w'], 2);
$res->d3w = number_format($_3way['d3w'], 2);
$res->a3w = number_format($_3way['a3w'], 2);
$res->flags = 1;
$res->margin = $_3way['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// ML
if (\count($ml) == 2) {
$ml['margin'] = (float) Margin::calculate($ml, 1);
$ml = array_merge($ml, $base);
$res = Odds2way::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds2way::create($ml);
} else {
$res->h2w = number_format($ml['h2w'], 2);
$res->a2w = number_format($ml['a2w'], 2);
$res->flags = 1;
$res->margin = $ml['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
if (\count($mls1) == 2) {
$mls1['margin'] = (float) Margin::calculate($mls1, 1);
$mls1 = array_merge($mls1, $base);
$res = Odds2wayS1::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds2wayS1::create($mls1);
} else {
$res->h2w = number_format($mls1['h2w'], 2);
$res->a2w = number_format($mls1['a2w'], 2);
$res->flags = 1;
$res->margin = $mls1['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// COLUMBIA
if ($c_totals) {
FilterHandicap::filter($_spreads['total'], 'IH_OUHND@', $c_totals, ['over', 'under', 'total']);
}
if ($c_points) {
FilterHandicap::filter($_spreads['point'], 'IH_12HND@', $c_points, ['hth1', 'hth2', 'hcap']);
}
// NIGERIA
if ($n_totals) {
FilterHandicap::filter($_spreads['total'], 'IH_TF@', $n_totals, ['over', 'under', 'total']);
}
if ($n_points) {
FilterHandicap::filter($_spreads['point'], 'IH_HR1@', $n_points, ['hth1', 'hth2', 'hcap']);
}
if (isset($_spreads['total'])) {
LogifutureStoreTotals::store($_spreads['total'], $base);
}
if (isset($_spreads['total_qt'])) {
LogifutureStoreTotalsQ1::store($_spreads['total_qt'], $base);
}
if (isset($_spreads['point'])) {
LogifutureStorePoints::store($_spreads['point'], $base);
}
if (isset($_spreads['point_qt'])) {
LogifutureStorePointsQ1::store($_spreads['point_qt'], $base);
}
}
}
@@ -0,0 +1,202 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture;
use App\Console\Commands\Nuh;
use App\Models\Odds3way;
use App\Models\OddsDc;
use App\Models\OddsGgng;
use App\Models\OddsTotal;
use App\Models\OddsTq;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class Soccer
{
public static function get(&$event, $match)
{
$_3way = [];
$_total = [];
$_ggng = [];
$_dc = [];
$_tq = [];
foreach ($match['odds'] as $name => $value) {
switch ($name) {
case 'S_1X2_1':
$_3way['h3w'] = number_format($value, 2);
break;
case 'S_1X2_X':
$_3way['d3w'] = number_format($value, 2);
break;
case 'S_1X2_2':
$_3way['a3w'] = number_format($value, 2);
break;
case 'S_OU@2.5_O':
$_total['over'] = number_format($value, 2);
break;
case 'S_OU@2.5_U':
$_total['under'] = number_format($value, 2);
break;
case 'S_GGNG_Y':
$_ggng['gg'] = number_format($value, 2);
break;
case 'S_GGNG_N':
$_ggng['ng'] = number_format($value, 2);
break;
// case 'S_DNB_1':
// break;
// case 'S_DNB_2':
// break;
case 'S_DC_12':
$_dc['dc12'] = number_format($value, 2);
break;
case 'S_DC_1X':
$_dc['dc1x'] = number_format($value, 2);
break;
case 'S_DC_X2':
$_dc['dcx2'] = number_format($value, 2);
break;
case 'S_12QUALIFY_1':
$_tq['htq'] = number_format($value, 2);
break;
case 'S_12QUALIFY_2':
$_tq['atq'] = number_format($value, 2);
break;
}
}
$base = [];
$base['event_id'] = $event['id'];
$base['bookmaker_id'] = $event['bookmaker_id'];
$base['sport_id'] = $event['sport_id'];
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event['event_id'];
$base['flags'] = 1;
// 1x2
if (\count($_3way) == 3) {
$_3way['margin'] = (float) Margin::calculate($_3way, 1);
$_3way = array_merge($_3way, $base);
$res = Odds3way::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds3way::create($_3way);
} else {
$res->h3w = number_format($_3way['h3w'], 2);
$res->d3w = number_format($_3way['d3w'], 2);
$res->a3w = number_format($_3way['a3w'], 2);
$res->flags = 1;
$res->margin = $_3way['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// OU
if (\count($_total) == 2) {
$_total['margin'] = (float) Margin::calculate($_total, 1);
$_total['total'] = 2.5;
$_total['active_spread'] = 1;
$_total = array_merge($_total, $base);
$res = OddsTotal::where('event_id', $event['id'])
->where('bookmaker_id', $event['bookmaker_id'])
->where('total', $_total['total'])
->first();
if (! $res) {
OddsTotal::create($_total);
} else {
$res->over = number_format($_total['over'], 2);
$res->under = number_format($_total['under'], 2);
$res->flags = 1;
$res->margin = $_total['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// GG NG
if (\count($_ggng) == 2) {
$_ggng['margin'] = (float) Margin::calculate($_ggng, 1);
$_ggng = array_merge($_ggng, $base);
$res = OddsGgng::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
OddsGgng::create($_ggng);
} else {
$res->gg = number_format($_ggng['gg'], 2);
$res->ng = number_format($_ggng['ng'], 2);
$res->flags = 1;
$res->margin = $_ggng['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// DC
if (\count($_dc) == 3) {
$_dc['margin'] = (float) Margin::calculate($_dc, 1);
$_dc = array_merge($_dc, $base);
$res = OddsDc::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
OddsDc::create($_dc);
} else {
$res->dc1x = number_format($_dc['dc1x'], 2);
$res->dc12 = number_format($_dc['dc12'], 2);
$res->dcx2 = number_format($_dc['dcx2'], 2);
$res->flags = 1;
$res->margin = $_dc['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
// TQ
if (\count($_tq) == 2) {
$_tq['margin'] = (float) Margin::calculate($_tq, 1);
$_tq = array_merge($_tq, $base);
$res = OddsTq::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
OddsTq::create($_tq);
} else {
$res->htq = number_format($_tq['htq'], 2);
$res->atq = number_format($_tq['atq'], 2);
$res->flags = 1;
$res->margin = $_tq['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,146 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture;
use App\Console\Commands\Grapper\Logifuture\Tools\FilterHandicap;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStorePoints;
use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStoreTotals;
use App\Console\Commands\Nuh;
use App\Models\Odds2way;
use App\Models\Odds2wayS1;
use App\Utilities\Margin;
use App\Utilities\Notice;
use Illuminate\Support\Facades\DB;
class Tennis
{
public static function get(&$event, $match)
{
$ml = [];
$mls1 = [];
$n_totals = [];
$n_points = [];
$c_totals = [];
$c_points = [];
foreach ($match['odds'] as $name => $value) {
switch ($name) {
case 'T_12_1':
$ml['h2w'] = number_format($value, 2);
break;
case 'T_12_2':
$ml['a2w'] = number_format($value, 2);
break;
case 'T_121P_1':
$mls1['h2w'] = number_format($value, 2);
break;
case 'T_121P_2':
$mls1['a2w'] = number_format($value, 2);
break;
}
if (strpos($name, '@') !== false) {
$pos = strpos($name, '@');
$market = substr($name, 0, $pos);
switch ($market) {
// NIGERIA
case 'T_OUG':
$n_totals[$name] = $value;
$c_totals[$name] = $value;
break;
case 'T_GH':
$n_points[$name] = $value;
break;
// COLOMBIA
case 'T_HNDGAMES':
$c_points[$name] = $value;
break;
}
}
}
$base = [];
$base['event_id'] = $event['id'];
$base['bookmaker_id'] = $event['bookmaker_id'];
$base['sport_id'] = $event['sport_id'];
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = $event['event_id'];
$base['flags'] = 1;
// ML
if (\count($ml) == 2) {
$ml['margin'] = (float) Margin::calculate($ml, 1);
$ml = array_merge($ml, $base);
// Notice::note($ml, 'g');
$res = Odds2way::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds2way::create($ml);
} else {
$res->h2w = number_format($ml['h2w'], 2);
$res->a2w = number_format($ml['a2w'], 2);
$res->flags = 1;
$res->margin = $ml['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
if (\count($mls1) == 2) {
$mls1['margin'] = (float) Margin::calculate($mls1, 1);
$mls1 = array_merge($mls1, $base);
$res = Odds2wayS1::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first();
if (! $res) {
Odds2wayS1::create($ml);
} else {
$res->h2w = number_format($ml['h2w'], 2);
$res->a2w = number_format($ml['a2w'], 2);
$res->flags = 1;
$res->margin = $mls1['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
$_spreads = [];
// COLUMBIA
if ($c_totals) {
FilterHandicap::filter($_spreads['total'], 'T_OUG@', $c_totals, ['over', 'under', 'total']);
}
if ($c_points) {
FilterHandicap::filter($_spreads['point'], 'T_HNDGAMES@', $c_points, ['hth1', 'hth2', 'hcap']);
}
// NIGERIA
if ($n_totals) {
FilterHandicap::filter($_spreads['total'], 'T_OUG@', $n_totals, ['over', 'under', 'total']);
}
if ($n_points) {
FilterHandicap::filter($_spreads['point'], 'T_GH@', $n_points, ['hth1', 'hth2', 'hcap']);
}
if (isset($_spreads['total'])) {
LogifutureStoreTotals::store($_spreads['total'], $base);
}
if (isset($_spreads['point'])) {
LogifutureStorePoints::store($_spreads['point'], $base);
}
}
}
@@ -0,0 +1,35 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
class ActiveHandicap
{
public static function set(&$_spreads)
{
$tmp = 10000;
$hcap = false;
foreach ($_spreads as $key => $value) {
$x = 0;
foreach ($value as $k => $v) {
if ($x == 0) {
$x = $v;
} else {
$x -= $v;
}
}
$x = abs($x);
if ($x < $tmp) {
$hcap = $key;
$tmp = $x;
}
}
foreach ($_spreads as $key => $value) {
if ($key == $hcap) {
$_spreads[$key]['active_spread'] = 1;
} else {
$_spreads[$key]['active_spread'] = 0;
}
}
}
}
@@ -0,0 +1,75 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
use App\Console\Commands\Grapper\Logifuture;
use App\Console\Commands\Nuh;
use App\Utilities\Notice;
class Authentication
{
public static function authenticate()
{
$debug = Nuh::$options['d'] ?? 0;
$url = Nuh::$options['base_url'].'/v1/authentication/token';
if (config('env.app_env') == 'local') {
/*************************************************
* PROXY
*************************************************/
if ($debug) {
Notice::note('AUTH with PROXY'.PHP_EOL.$url, 'p');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://prox1.nuhodds.com/proxy_logi_auth.php');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['url' => $url, 'password' => config('env.logifuture_token')]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Proxy-Auth: AIkcoRnipSgMK88WMQhOQQN3LKDrNDCIebNfPnEayJdmDeTigx',
]);
} else {
/*************************************************
* DIRECT
*************************************************/
if ($debug) {
Notice::note('AUTH direct'.PHP_EOL.$url, 'b');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'username' => 'nuhodds',
'password' => config('env.logifuture_token'),
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'accept: application/json',
'content-type: application/json',
]);
}
$file = curl_exec($ch);
$data = json_decode($file, true);
$header = [];
$header[] = 'Authorization: Bearer '.$data['token'];
$header[] = 'accept: application/json';
$header[] = 'content-type: application/json';
Logifuture::$auth_header = $header;
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
class FilterHandicap
{
public static function filter(&$_spreads, $filter, $data, $oddnames)
{
foreach ($data as $key => $value) {
$key = str_replace($filter, '', $key);
if (strpos($key, '_O') !== false) {
$hcap = str_replace('_O', '', $key);
$_spreads[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_1H') !== false) {
$hcap = str_replace('_1H', '', $key);
$_spreads[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_1') !== false) {
$hcap = str_replace('_1', '', $key);
$_spreads[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_U') !== false) {
$hcap = str_replace('_U', '', $key);
$_spreads[$hcap]['ele2'] = $value;
} elseif (strpos($key, '_2H') !== false) {
$hcap = str_replace('_2H', '', $key);
$_spreads[$hcap]['ele2'] = $value;
} elseif (strpos($key, '_2') !== false) {
$hcap = str_replace('_2', '', $key);
$_spreads[$hcap]['ele2'] = $value;
}
}
}
}
@@ -0,0 +1,91 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
use App\Console\Commands\Grapper\Logifuture;
use App\Console\Commands\Nuh;
use App\Utilities\Notice;
class LogifutureData
{
public static $testfiles = '/Console/Commands/TestFiles/';
public static function load($logifuture_sport_id)
{
$debug = Nuh::$options['d'] ?? 0;
$save = Nuh::$options['s'] ?? 0;
$read = Nuh::$options['r'] ?? 0;
$filename = app_path().self::$testfiles.str_replace(' ', '_', strtolower(Nuh::$options['sport'].'_'.Nuh::$options['provider'])).'.json';
if ($read) {
if ($debug) {
Notice::note('data read localy', 'g');
}
$file = file_get_contents($filename);
return json_decode($file, true);
}
$url = Nuh::$options['base_url'].'/v1/matches?sportId='.$logifuture_sport_id;
if (config('env.app_env') == 'local') {
/*************************************************
* PROXY
*************************************************/
if ($debug) {
Notice::note('DATA with PROXY'.PHP_EOL.$url, 'p');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://prox1.nuhodds.com/proxy_logi_data.php');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'url' => $url,
'header' => json_encode(Logifuture::$auth_header),
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Proxy-Auth: AIkcoRnipSgMK88WMQhOQQN3LKDrNDCIebNfPnEayJdmDeTigx',
]);
} else {
/*************************************************
* DIRECT
*************************************************/
if ($debug) {
Notice::note('DATA direct'.PHP_EOL.$url, 'b');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, Logifuture::$auth_header);
}
$file = curl_exec($ch);
if ($save) {
file_put_contents($filename, $file);
Notice::note('file saved localy', 'g');
}
if (curl_errno($ch)) {
echo curl_error($ch);
}
return json_decode($file, true);
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
use App\Models\OddsPoint;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class LogifutureStorePoints
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $handicap => $value) {
// code...
$odds = [];
$odds['home'] = $value['ele1'];
$odds['away'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['handicap'] = $handicap;
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds['flags'] = 1;
$odds = array_merge($odds, $base);
$res = OddsPoint::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPoint::create($odds);
} else {
$res->home = number_format($odds['home'], 2);
$res->away = number_format($odds['away'], 2);
$res->handicap = number_format($odds['handicap'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
use App\Models\OddsPointQ1;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class LogifutureStorePointsQ1
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $handicap => $value) {
// code...
$odds = [];
$odds['home'] = $value['ele1'];
$odds['away'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['handicap'] = $handicap;
$odds['flags'] = 1;
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds = array_merge($odds, $base);
$res = OddsPointQ1::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPointQ1::create($odds);
} else {
$res->home = number_format($odds['home'], 2);
$res->away = number_format($odds['away'], 2);
$res->handicap = number_format($odds['handicap'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
use App\Models\OddsTotal;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class LogifutureStoreTotals
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $total => $value) {
// code...
$odds = [];
$odds['over'] = $value['ele1'];
$odds['under'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['flags'] = 1;
$odds['total'] = $total;
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds = array_merge($odds, $base);
$res = OddsTotal::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotal::create($odds);
} else {
$res->over = number_format($odds['over'], 2);
$res->under = number_format($odds['under'], 2);
$res->total = number_format($odds['total'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
use App\Models\OddsTotalQ1;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class LogifutureStoreTotalsQ1
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $total => $value) {
// code...
$odds = [];
$odds['over'] = $value['ele1'];
$odds['under'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['flags'] = 1;
$odds['total'] = $total;
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds = array_merge($odds, $base);
$res = OddsTotalQ1::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotalQ1::create($odds);
} else {
$res->over = number_format($odds['over'], 2);
$res->under = number_format($odds['under'], 2);
$res->total = number_format($odds['total'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,35 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
use App\Console\Commands\Nuh;
use Illuminate\Support\Carbon;
class MapEvent
{
public static function filter($sport_id, $match)
{
$event = [];
$event['event_id'] = (int) $match['id'];
$event['bookmaker_id'] = Nuh::$options['bookmaker_id'];
$event['betradar_id'] = (int) preg_replace('"\D"', '', $match['externalId']);
$event['sport_id'] = $sport_id;
$event['provider_id'] = Nuh::$options['provider_id'];
$event['starttime'] = Carbon::parse($match['startDate'])->toDateTimeString();
$event['country'] = $match['sportCategory'];
$event['group_id'] = (int) $match['tournamentId'];
$event['group'] = addslashes($match['tournamentName']);
$str = str_replace('||', '|', $match['description']);
$str = trim(str_replace('|', ' ', $str));
if (Nuh::$options['bookmaker_id'] == 36) {
$teams = explode(' v ', $str);
} else {
$teams = explode(' - ', $str);
}
$event['home'] = addslashes($teams[0]);
$event['away'] = addslashes($teams[1]);
return $event;
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\Magloo\Fixtures;
use App\Console\Commands\Grapper\Magloo\Odds;
use App\Console\Commands\Nuh;
use App\Utilities\Notice;
class Magloo
{
public static function switch()
{
switch (Nuh::$options['name']) {
case 'Fixtures':
Fixtures::grap();
break;
case 'Odds':
Odds::grap();
break;
default:
Notice::note('prosses name does not exist', 'r', 1);
break;
}
}
}
@@ -0,0 +1,132 @@
<?php
namespace App\Console\Commands\Grapper\Magloo;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Fixtures\FindFixture;
use App\Console\Commands\Nuh;
use App\Models\EventBookmaker;
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;
$proxy = Nuh::$options['p'] ?? 0;
FindFixture::start();
$sportmap = Sport::map('magl', false, [1, 3]);
// dd($sportmap);
if ($proxy) {
Notice::note('PROXY USED', 'r');
}
if ($debug) {
Notice::note(Nuh::$options['provider'].' '.Nuh::$options['name'], 'g');
}
foreach ($sportmap as $sport_id => $magloo_sport_id) {
$event_id_collector = [];
/**
* Tornaments
*/
$url = Nuh::$options['base_url'].'/en/'.$magloo_sport_id.'/prematch/sport';
$data = Curl::load($url);
if (is_array($data) or \count($data)) {
$ligas = [];
foreach ($data as $value) {
$tmp = [];
if ($value['i'] == $magloo_sport_id) {
$tmp['sport'] = $value['n'];
$tmp['sport_id'] = $sport_id;
foreach ($value['C'] as $key => $val1) {
$tmp['country_id'] = $val1['i'];
$tmp['country'] = $val1['n'];
foreach ($val1['T'] as $key => $val2) {
$tmp['group_id'] = $val2['i'];
$tmp['group'] = $val2['n'];
$ligas[] = $tmp;
}
}
}
}
foreach ($ligas as $liga) {
// 19 => array:6 [
// "sport" => "Basketball"
// "sport_id" => 3
// "country_id" => 146
// "country" => "Israel"
// "group_id" => 525
// "group" => "Super League"
// ]
if ($liga['group'] && strpos($liga['group'], 'Simulated') === false) {
$sport_id = $liga['sport_id'];
$url = Nuh::$options['base_url'].'/en/'.$magloo_sport_id.'/prematch/tournament/'.$liga['group_id'].'/event';
$data = Curl::load($url);
if (! count($data)) {
return;
}
foreach ($data as $magloo) {
$event = [];
$event['event_id'] = (int) $magloo['i'];
$event['betradar_id'] = (int) preg_replace('/\D/', '', $magloo['p']);
$event['sport_id'] = $sport_id;
$event['provider_id'] = Nuh::$options['provider_id'];
$event['country_id'] = $liga['country_id'];
$event['country'] = $liga['country'];
$event['group_id'] = $liga['group_id'];
$event['group'] = $liga['group'];
$event['starttime'] = Carbon::parse($magloo['dt'])->toDateTimeString();
$teams = explode(' v ', str_replace('|', ' ', $magloo['n']));
$event['home_id'] = $magloo['htId'];
$event['home'] = addslashes($teams[0]);
$event['away_id'] = $magloo['atId'];
$event['away'] = addslashes($teams[1]);
FindFixture::find($event);
if (isset($event['id'])) {
$event_id_collector[] = $event['id'];
DB::transaction(function () use ($event, $sport_id) {
EventBookmaker::updateOrCreate([
'event_id' => $event['id'],
'sport_id' => $sport_id,
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], ['in_feed' => 1, 'bmoid' => $event['event_id'], 'starttime' => $event['starttime']]);
}, 5);
}
}
}
}
if ($event_id_collector) {
EventBookmaker::whereNotIn('event_id', $event_id_collector)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->update(['in_feed' => 0]);
}
}
}
}
}
@@ -0,0 +1,156 @@
<?php
namespace App\Console\Commands\Grapper\Magloo;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\Magloo\Odds\FilterHandicap;
use App\Console\Commands\Grapper\Magloo\Odds\FilterHandicapQ1;
use App\Console\Commands\Grapper\Magloo\Odds\FilterTotals;
use App\Console\Commands\Grapper\Magloo\Odds\FilterTotalsQ1;
use App\Console\Commands\Grapper\Magloo\Odds\MaglooStore1x2;
use App\Console\Commands\Grapper\Magloo\Odds\MaglooStoreDc;
use App\Console\Commands\Grapper\Magloo\Odds\MaglooStoreGgng;
use App\Console\Commands\Grapper\Magloo\Odds\MaglooStorePoints;
use App\Console\Commands\Grapper\Magloo\Odds\MaglooStorePointsQ1;
use App\Console\Commands\Grapper\Magloo\Odds\MaglooStoreTotals;
use App\Console\Commands\Grapper\Magloo\Odds\MaglooStoreTotalsQ1;
use App\Console\Commands\Grapper\Magloo\Odds\MaglooStoreTq;
use App\Console\Commands\Nuh;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\Sport;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class Odds
{
public static function grap()
{
$debug = Nuh::$options['d'] ?? 0;
$proxy = Nuh::$options['p'] ?? 0;
$event_id_collector = [];
$sportmap = Sport::map('magl', 1, [1, 3]);
if ($proxy) {
Notice::note('PROXY USED', 'r');
}
if ($debug) {
Notice::note(Nuh::$options['provider'].' '.Nuh::$options['name'], 'g');
}
foreach ($sportmap as $magloo_sport_id => $sport_id) {
$url = Nuh::$options['base_url'].'/1/prematch/sport/'.$magloo_sport_id.'/odds';
$data = Curl::load($url, ['timeout' => 30]);
if (! is_array($data) or \count($data) == 0) {
Notice::note('no data in feed', 'r', 1);
return;
}
foreach ($data as $match) {
$betradar_id = (int) preg_replace('/\D/', '', $match['p']);
$starttime = Carbon::parse($match['dt'])->toDateTimeString();
$event_id = Event::where('betradar_id', $betradar_id)->value('id');
if ($event_id) {
$base = [];
$base['event_id'] = $event_id;
$base['bookmaker_id'] = Nuh::$options['bookmaker_id'];
$base['sport_id'] = $sport_id;
$base['provider_id'] = Nuh::$options['provider_id'];
$base['bmoid'] = preg_replace('/\D/', '', $match['i']);
$base['flag'] = 1;
$event_id_collector[] = $event_id;
EventBookmaker::updateOrCreate([
'event_id' => $event_id,
'sport_id' => $sport_id,
'bookmaker_id' => Nuh::$options['bookmaker_id'],
], ['starttime' => $starttime, 'in_feed' => 1, 'bmoid' => $base['bmoid']]);
// if ($event_id == 14190947) {
// dd($match['M']);
// }
foreach ($match['M'] as $magloo_bettype_id => $value) {
switch ($magloo_bettype_id) {
case 1:
// 1x2
MaglooStore1x2::store($value, $base);
break;
case 2:
// to qalify
MaglooStoreTq::store($value, $base);
break;
case 10:
// double chance
MaglooStoreDc::store($value, $base);
break;
case 27:
// ggng
MaglooStoreGgng::store($value, $base);
break;
case 16:
case 2000:
// points
$odds = FilterHandicap::get($value);
MaglooStorePoints::store($odds, $base);
break;
case 2025:
// points qt
$odds = FilterHandicapQ1::get($value);
MaglooStorePointsQ1::store($odds, $base);
break;
case 17:
case 2002:
// totals
$odds = FilterTotals::get($value, $sport_id);
MaglooStoreTotals::store($odds, $base);
break;
case 2012:
// totals qt
$odds = FilterTotalsQ1::get($value, $sport_id);
MaglooStoreTotalsQ1::store($odds, $base);
break;
}
}
}
}
}
EventBookmaker::whereNotIn('event_id', $event_id_collector)
->where('bookmaker_id', Nuh::$options['bookmaker_id'])
->update(['in_feed' => 0]);
$tables = ['odds_3ways', 'odds_dc', 'odds_ggng', 'odds_points', 'odds_points_q1', 'odds_totals', 'odds_totals_q1', 'odds_tq'];
foreach ($tables as $table) {
DB::table($table)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->whereNotIn('event_id', $event_id_collector)->update(['flags' => 0]);
}
}
}
@@ -0,0 +1,35 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
class ActiveHandicap
{
public static function set(&$_spreads)
{
$tmp = 10000;
$hcap = false;
foreach ($_spreads as $key => $value) {
$x = 0;
foreach ($value as $k => $v) {
if ($x == 0) {
$x = $v;
} else {
$x -= $v;
}
}
$x = abs($x);
if ($x < $tmp) {
$hcap = $key;
$tmp = $x;
}
}
foreach ($_spreads as $key => $value) {
if ($key == $hcap) {
$_spreads[$key]['active_spread'] = 1;
} else {
$_spreads[$key]['active_spread'] = 0;
}
}
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Console\Commands\Grapper\Logifuture\Tools\ActiveHandicap;
class FilterHandicap
{
public static function get($_spreads)
{
ActiveHandicap::set($_spreads);
$_points = [];
foreach ($_spreads as $handicap => $value) {
if (fmod(abs($handicap), 1) == 0.5) {
if ($value[1714] > 1 and $value[1715] > 1) {
$_points[$handicap]['home'] = number_format($value[1714], 2);
$_points[$handicap]['away'] = number_format($value[1715], 2);
}
}
}
return $_points;
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
class FilterHandicapQ1
{
public static function get($_array)
{
$_points = [];
foreach ($_array as $key => $value) {
$t = explode('_', $key);
$matchpart = $t[0];
$handicap = (float) $t[1];
if ($matchpart == 1) {
if (fmod(abs($handicap), 1) == 0.5) {
if ($value[1714] > 1 and $value[1715] > 1) {
$_points[$handicap]['home'] = number_format($value[1714], 2);
$_points[$handicap]['away'] = number_format($value[1715], 2);
}
}
}
}
return $_points;
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
class FilterTotals
{
public static function get($_array, $sport_id)
{
$_totals = [];
foreach ($_array as $total => $value) {
if ($sport_id == 1) {
if ($total == 2.5) {
if ($value[12] > 1 and $value[13] > 1) {
$_totals[$total]['over'] = number_format($value[12], 2);
$_totals[$total]['under'] = number_format($value[13], 2);
}
}
} else {
if (fmod(abs($total), 1) == 0.5) {
if ($value[12] > 1 and $value[13] > 1) {
$_totals[$total]['over'] = number_format($value[12], 2);
$_totals[$total]['under'] = number_format($value[13], 2);
}
}
}
}
return $_totals;
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
class FilterTotalsQ1
{
public static function get($_array, $sport_id)
{
$_totals = [];
foreach ($_array as $key => $value) {
$t = explode('_', $key);
$matchpart = $t[0];
$total = (float) $t[1];
if ($matchpart == 1) {
if (fmod(abs($total), 1) == 0.5) {
if ($value[12] > 1 and $value[13] > 1) {
$_totals[$total]['over'] = number_format($value[12], 2);
$_totals[$total]['under'] = number_format($value[13], 2);
}
}
}
}
return $_totals;
}
}
@@ -0,0 +1,37 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\Odds3way;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStore1x2
{
public static function store($value, $base)
{
$odds = [];
$odds['h3w'] = number_format($value['static'][1], 2) ?? 1;
$odds['d3w'] = number_format($value['static'][2], 2) ?? 1;
$odds['a3w'] = number_format($value['static'][3], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['flags'] = 1;
$odds = array_merge($odds, $base);
$res = Odds3way::where('event_id', $base['event_id'])->where('bookmaker_id', $base['bookmaker_id'])->first();
if (! $res) {
Odds3way::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->d3w = $odds['d3w'];
$res->a3w = $odds['a3w'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsDc;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStoreDc
{
public static function store($value, $base)
{
$odds = [];
$odds['dc1x'] = number_format($value['static'][9], 2) ?? 1;
$odds['dc12'] = number_format($value['static'][10], 2) ?? 1;
$odds['dcx2'] = number_format($value['static'][11], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['flags'] = 1;
$odds = array_merge($odds, $base);
$res = OddsDc::where('event_id', $base['event_id'])->where('bookmaker_id', $base['bookmaker_id'])->first();
if (! $res) {
OddsDc::create($odds);
} else {
$res->dc1x = $odds['dc1x'];
$res->dc12 = $odds['dc12'];
$res->dcx2 = $odds['dcx2'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
@@ -0,0 +1,36 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsGgng;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStoreGgng
{
public static function store($value, $base)
{
$odds = [];
$odds['gg'] = number_format($value['static'][74], 2) ?? 1;
$odds['ng'] = number_format($value['static'][76], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['flags'] = 1;
$odds = array_merge($odds, $base);
$res = OddsGgng::where('event_id', $base['event_id'])->where('bookmaker_id', $base['bookmaker_id'])->first();
if (! $res) {
OddsGgng::create($odds);
} else {
$res->gg = $odds['gg'];
$res->ng = $odds['ng'];
$res->flags = 1;
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsPoint;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStorePoints
{
public static function store($data, $base)
{
ActiveHandicap::set($data);
foreach ($data as $handicap => $value) {
$odds = $value;
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
$odds['active_spread'] = $value['active_spread'];
$odds['handicap'] = $handicap;
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds['flags'] = 1;
$odds = array_merge($odds, $base);
$res = OddsPoint::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPoint::create($odds);
} else {
$res->flags = 1;
$res->home = number_format($odds['home'], 2);
$res->away = number_format($odds['away'], 2);
$res->handicap = number_format($odds['handicap'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsPointQ1;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStorePointsQ1
{
public static function store($data, $base)
{
ActiveHandicap::set($data);
foreach ($data as $handicap => $value) {
$odds = $value;
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
$odds['active_spread'] = $value['active_spread'];
$odds['handicap'] = $handicap;
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds['flags'] = 1;
$odds = array_merge($odds, $base);
$res = OddsPointQ1::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPointQ1::create($odds);
} else {
$res->flags = 1;
$res->home = number_format($odds['home'], 2);
$res->away = number_format($odds['away'], 2);
$res->handicap = number_format($odds['handicap'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsTotal;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStoreTotals
{
public static function store($data, $base)
{
ActiveHandicap::set($data);
foreach ($data as $total => $value) {
$odds = $value;
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
$odds['active_spread'] = $value['active_spread'];
$odds['total'] = $total;
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds['flags'] = 1;
$odds = array_merge($odds, $base);
$res = OddsTotal::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotal::create($odds);
} else {
$res->flags = 1;
$res->over = number_format($odds['over'], 2);
$res->under = number_format($odds['under'], 2);
$res->total = number_format($odds['total'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsTotalQ1;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStoreTotalsQ1
{
public static function store($data, $base)
{
ActiveHandicap::set($data);
foreach ($data as $total => $value) {
$odds = $value;
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
$odds['active_spread'] = $value['active_spread'];
$odds['total'] = $total;
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds['flags'] = 1;
$odds = array_merge($odds, $base);
$res = OddsTotalQ1::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotalQ1::create($odds);
} else {
$res->flags = 1;
$res->over = number_format($odds['over'], 2);
$res->under = number_format($odds['under'], 2);
$res->total = number_format($odds['total'], 2);
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
}
@@ -0,0 +1,36 @@
<?php
namespace App\Console\Commands\Grapper\Magloo\Odds;
use App\Models\OddsTq;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class MaglooStoreTq
{
public static function store($value, $base)
{
$odds = [];
$odds['htq'] = number_format($value['static'][4], 2) ?? 1;
$odds['atq'] = number_format($value['static'][5], 2) ?? 1;
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds = array_merge($odds, $base);
$odds['flags'] = 1;
$res = OddsTq::where('event_id', $base['event_id'])->where('bookmaker_id', $base['bookmaker_id'])->first();
if (! $res) {
OddsTq::create($odds);
} else {
$res->flags = 1;
$res->htq = $odds['htq'];
$res->atq = $odds['atq'];
$res->margin = $odds['margin'];
DB::transaction(function () use ($res) {
$res->save();
}, 5);
}
}
}
@@ -0,0 +1,177 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grap;
use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa;
use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper;
use App\Models\Country;
use App\Models\SofaScoreCategory;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreTournament;
use App\Utilities\Notice;
use Illuminate\Support\Facades\Log;
class DaysTournament
{
/**
* a Grap --d --f 67 --fun=4 --task=1
*
* Ita Serie-A-Saison 23-08-2025 - 24-05-2026
* Ger Bundesliga 22-08-2025 – 16-05-2026
* Eng Premier league 15-08-2025 - 24-05-2026
* Spa La Liga 15-08-2025 - 24-05-2026
* Fra Liggue 15-08-2025 - 17-05-2026
*/
public static function get(string $day)
{
$debug = Grap::$options['d'] ?? 0;
$force = Grap::$options['F'] ?? 0;
$tournaments_counter = 0;
$has = SofaScoreDayTournament::where('day', $day)->first();
$sport = [];
$sport[1] = 'football';
foreach ($sport as $sport_id => $slug) {
if (!$force && $has) {
if ($debug) {
Notice::note("Tournaments $day for " . strtoupper($slug) . ' allready grapped', 'bb');
}
} else {
if ($debug) {
Notice::note("$day\ngrappig", 'g');
}
$page = 1;
while ($page) {
$url = Grap::$options['base_url'] . "api/v1/sport/$slug/scheduled-tournaments/$day/page/$page";
Sleeper::rand();
$data = CurlSofa::load($url);
if ($data['hasNextPage']) {
$page++;
} else {
$page = false;
}
foreach ($data['scheduled'] as $row) {
if (isset($row['tournament']['uniqueTournament'])) {
$tournament = $row['tournament']['uniqueTournament'];
} else {
$tournament = $row['tournament'];
}
$category = $tournament['category'];
if ($sport_id == 5) {
$country_id = 470;
} else {
/**
* CATEGORY
*/
$find = [
'Amateur',
'Bosnia & Herzegovina',
'Czechia',
'DR Congo',
'Netherlands',
'North & Central America',
'Bonaire',
'Sao Tome and Principe',
'Cape Verde',
'Macao',
'Saint Kitts and Nevis',
'Eswatini',
'Timor Leste',
'Laos',
'Congo Republic',
];
$replace = [
'',
'Bosnia Herzegovina',
'Czech Republic',
'Congo DR',
'Holland',
'North America',
'Bonaire, Sint Eustatius and Saba',
'Sao Tome e Principe',
'Cape Verde Islands',
'Macau',
'St. Kitts and Nevis',
'Swaziland',
'East Timor',
'Lao Peoples\'s Democratic Republic',
'Congo DR',
];
$country_id = Country::where('name', trim(str_replace($find, $replace, $category['name'])))->value('id');
}
// dd($category, $country_id);
if (! $country_id) {
// platzhalter fix later sofa_score_categories => txodds countries
// CATEGORY find <-> replace
// Log::channel('sofascore')->info($tournament);
$sofa_score_category_id = 10000000;
} else {
$call = SofaScoreCategory::updateOrCreate([
'id' => (int) $category['id'],
'country_id' => (int) $country_id,
'slug' => $category['slug'],
], [
'name' => $category['name'],
]);
$sofa_score_category_id = $call->id;
}
/**
* TOURNAMENT
*/
SofaScoreTournament::updateOrCreate([
'sport_id' => (int) $sport_id,
'tournament_id' => (int) $tournament['id'],
'sofa_score_category_id' => (int) $sofa_score_category_id,
], [
'name' => $tournament['name'],
'slug' => $tournament['slug'],
]);
$tournaments_counter++;
// if ($debug) {
// Notice::note('tournament: ' . $tournament['name'], 'p');
// }
/**
* DAY TOURNAMENT
*/
SofaScoreDayTournament::updateOrCreate([
'tournament_id' => (int) $tournament['id'],
'sport_id' => (int) $sport_id,
'day' => $day,
]);
}
if ($debug) {
Notice::note("tournaments: $tournaments_counter", 'p');
}
}
}
}
if ($debug) {
Notice::note('days tournament done', 'g');
}
}
}
@@ -0,0 +1,239 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grap;
use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa;
use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays;
use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreEventGrapped;
use App\Models\SofaScoreTaskDay;
use App\Models\SofaScoreTaskTournament;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File;
class Grapper
{
public static function load(int $task_id)
{
/**
* , JSON_PRETTY_PRINT
* to fromat json
*/
$debug = Grap::$options['d'] ?? 0;
$restart = Grap::$options['r'] ?? 0;
$force = Grap::$options['f'] ?? 0;
if (! $task_id) {
Notice::note('task id missing', 'r', 1);
}
$days = LoadDays::load($task_id);
$count = 0;
/** take for task 2 the same like for task 1 */
switch ($task_id) {
case 1:
case 2:
$active_tournaments = SofaScoreTaskTournament::with('tournament')->where('sofa_score_task_id', 1)->where('disabled', false)->get();
break;
default:
$active_tournaments = SofaScoreTaskTournament::with('tournament')->where('sofa_score_task_id', $task_id)->where('disabled', false)->get();
// $active_tournaments = SofaScoreTaskTournament::with('tournament')->where('sofa_score_tournament_id', 247)->where('sofa_score_task_id', $task_id)->where('disabled', false)->get();
break;
}
/**
* Restart
*/
if ($restart) {
SofaScoreEventGrapped::where('grapper_id', $task_id)->delete();
foreach ($days as $day) {
// if restarting find position
SofaScoreTaskDay::where('grapper_id', (int) $task_id)
->where('day', $day)
->update(['done' => 0]);
}
if ($debug) {
Notice::note('Restarted grapper', 'br', 1);
}
}
foreach ($days as $day) {
DaysTournament::get($day);
dd($active_tournaments);
foreach ($active_tournaments as $tournament) {
$res = SofaScoreDayTournament::whereDate('day', '=', $day)->where('tournament_id', $tournament->sofa_score_tournament_id)->first();
if ($res) {
if ($debug) {
Notice::note($tournament->sofa_score_tournament_id, 'bb');
}
if (! $force) {
Sleeper::rand(1);
} else {
Sleeper::rand();
}
if ($debug) {
Notice::note($day, 'br');
}
$url = Grap::$options['base_url']."api/v1/unique-tournament/$tournament->sofa_score_tournament_id/scheduled-events/$day";
$data = CurlSofa::load($url);
Notice::note($data, 'bb');
if (isset($data['events'])) {
if ($debug) {
Notice::note($tournament->tournament->name, 'bb');
}
foreach ($data['events'] as $event) {
Grap::$useragent = rand(1, 6);
if (! $force && SofaScoreEventGrapped::where('grapper_id', $task_id)->where('id', (int) $event['id'])->exists()) {
if ($debug) {
Notice::note('DB - Allready grapped at '.$day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'g');
}
} else {
$now = Carbon::now()->subHours(3);
$carbon_day = new Carbon($day);
$starttime = Carbon::createFromTimestamp($event['startTimestamp']);
// dd($starttime);
// if ($now->greaterThan($starttime) && $starttime->isSameDay($carbon_day)) {
if (! $force) {
Sleeper::rand(1);
} else {
Sleeper::rand();
}
if ($debug) {
Notice::note($day.' - '.$event['homeTeam']['name'].' vs '.$event['awayTeam']['name'], 'bg');
}
$folder = strtolower(Grap::$storage.'/'.$day.'/'.$day.'-'.$event['tournament']['category']['slug'].'-'.$event['tournament']['slug'].'/'.$event['slug']);
File::makeDirectory($folder, 0775, true, true);
/*********************************
* EVENT event
*********************************/
File::put($folder.'/event.json', json_encode($event));
/*********************************
* EVENT statistics
*********************************/
$event_id = $event['id'];
$url = Grap::$options['base_url']."api/v1/event/$event_id/statistics";
Sleeper::rand();
$data = CurlSofa::load($url);
$data['id'] = $event_id;
File::put($folder.'/statistics.json', json_encode($data));
/*********************************
* EVENT lineups
*********************************/
$url = Grap::$options['base_url']."api/v1/event/$event_id/lineups";
Sleeper::rand();
$data = CurlSofa::load($url);
$data['id'] = $event_id;
File::put($folder.'/lineups.json', json_encode($data));
/*********************************
* EVENT odds
*********************************/
$url = Grap::$options['base_url']."api/v1/event/$event_id/odds/1/all";
Sleeper::rand();
$data = CurlSofa::load($url);
$data['id'] = $event_id;
File::put($folder.'/odds.json', json_encode($data));
/*********************************
* EVENT incidents
*********************************/
$url = Grap::$options['base_url']."api/v1/event/$event_id/incidents";
Sleeper::rand();
$data = CurlSofa::load($url);
$data['id'] = $event_id;
File::put($folder.'/incidents.json', json_encode($data));
$grapped = SofaScoreEventGrapped::firstOrNew(['id' => $event['id']]);
$grapped->grapper_id = $task_id;
$grapped->day = $day;
$grapped->liga = $event['tournament']['name'];
$grapped->name = $event['homeTeam']['name'].' vs '.$event['awayTeam']['name'];
$grapped->url = $url;
$grapped->starttime = $starttime->toDateTimeString();
$grapped->save();
// }
}
}
}
}
}
SofaScoreTaskDay::updateOrCreate([
'grapper_id' => (int) $task_id,
'day' => $day,
], [
'done' => 1,
]);
$count++;
if ($debug) {
Notice::note("$count days done, sleep 10-20 sec", 'p');
}
if (! $force) {
Sleeper::rand(2);
} else {
Sleeper::rand();
}
}
}
}
@@ -0,0 +1,71 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grap;
use App\Console\Commands\Grapper\Sofascore\Helper\CurlLivescore;
use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa;
use App\Utilities\Notice;
use DOMDocument;
use DOMXPath;
class GrapperTest
{
public static $testfiles = '/Testfiles/';
public static function load()
{
$read = Grap::$options['R'] ?? 0;
$save = Grap::$options['S'] ?? 0;
$testfile = 'livescore.txt';
$path = __DIR__ . self::$testfiles . $testfile;
Notice::note('Grapper testing ' . $testfile, 'b');
// $url = 'https://www.livescore.in/horse-racing/canada/woodbine-2020/';
$url = 'https://www.sofascore.com/api/v1/event/16298660/statistics';
$data = CurlSofa::load($url);
Notice::note($data, '', 1);
if ($read) {
Notice::note('data read localy', 'p');
$data = file_get_contents($path);
} else {
$data = CurlLivescore::load($url);
}
if ($save) {
file_put_contents($path, $data);
Notice::note('file saved localy', 'g');
}
$dom = new DOMDocument;
// Prevent warnings caused by HTML5 tags that native DOMDocument doesn't fully understand
libxml_use_internal_errors(true);
// Use mb_convert_encoding to ensure DOMDocument treats the input as UTF-8
$dom->loadHTML(mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8'));
libxml_clear_errors();
// 3. Use XPath to query specific HTML elements
$xpath = new DOMXPath($dom);
// Example: Target match rows or team names (Update classes based on actual DOM structure)
// Modern livescore sites often use classes like '.event__match' or '.event__participant'
$teams = $xpath->query("//div[contains(@class, 'event__participant')]");
foreach ($teams as $team) {
echo trim($team->nodeValue) . PHP_EOL;
}
Notice::note($data, 'p', 1);
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Grap;
use App\Utilities\Notice;
use Illuminate\Filesystem\Filesystem;
class ClearDir
{
public static function clear($dir = ''): void
{
$file = new Filesystem;
$debug = Grap::$options['d'];
if ($dir) {
$file->cleanDirectory($dir);
if ($debug) {
Notice::note('Folder removed', 'br');
}
} else {
$file->cleanDirectory(Grap::$storage);
if ($debug) {
Notice::note('Folder content deleted', 'br');
}
}
}
}
@@ -0,0 +1,82 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Grap;
use App\Utilities\Notice;
class CurlSofa
{
public static function load(string $url)
{
$debug = Grap::$options['d'] ?? 0;
if ($debug) {
Notice::note($url, 'b');
}
// $useragents = [];
// $useragents[1] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36";
// $useragents[2] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36";
// $useragents[3] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15";
// $useragents[4] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0";
// $useragents[5] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0";
// $useragents[6] = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36";
$useragents = [];
$useragents[1] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15';
$useragents[2] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15';
$useragents[3] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
$useragents[4] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15';
$useragents[5] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0';
$useragents[6] = 'Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36';
// GET /api/v1/config/default-unique-tournaments/AT/football HTTP/2
// Host: www.sofascore.com
// User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:139.0) Gecko/20100101 Firefox/139.0
// Accept: */*
// Accept-Language: de,en-US;q=0.7,en;q=0.3
// Accept-Encoding: gzip, deflate, br, zstd
// Referer: https://www.sofascore.com/
// X-Requested-With: 629800
// DNT: 1
// Sec-GPC: 1
// Connection: keep-alive
// Sec-Fetch-Dest: empty
// Sec-Fetch-Mode: cors
// Sec-Fetch-Site: same-origin
// Priority: u=4
// Pragma: no-cache
// Cache-Control: no-cache
// TE: trailers
$headers = [
'User-Agent: '.$useragents[Grap::$useragent],
'Accept: */*',
'Accept-Language: de,en-US;q=0.7,en;q=0.3',
'Accept-Encoding: gzip, deflate, br, zstd',
'Referer: https://www.sofascore.com/',
'X-Requested-With: 629800',
'DNT: 1',
'Sec-GPC: 1',
'Connection: keep-alive',
'Sec-Fetch-Dest: empty',
'Sec-Fetch-Mode: cors',
'Sec-Fetch-Site: same-origin',
'Priority: u=4',
'Pragma: no-cache',
'Cache-Control: no-cache',
'TE: trailers',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// This line magically handles all decompression out-of-the-box:
curl_setopt($ch, CURLOPT_ENCODING, '');
$data = curl_exec($ch);
$data = json_decode($data, true);
return $data;
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
class FileType
{
public static function filter(array $files, array $types = ['json'])
{
$filtered = [];
foreach ($files as $file) {
$path_parts = pathinfo($file);
if (isset($path_parts['extension']) && in_array($path_parts['extension'], $types)) {
$filtered[] = $file;
}
}
return $filtered;
}
}
@@ -0,0 +1,97 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Grap;
use App\Models\SofaScoreTask;
use App\Models\SofaScoreTaskDay;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class LoadDays
{
public static function load(int $task_id)
{
$debug = Grap::$options['d'] ?? 0;
$restart = Grap::$options['r'] ?? 0;
$dates = [];
if (! $task_id) {
Notice::note('no task id', 'br');
return [];
}
$task = SofaScoreTask::with('sport')->where('id', $task_id)->first();
if ($debug) {
Notice::note('Task id:' . $task->id . ', mode:' . $task->mode . ', sport:' . $task->sport->name);
}
switch ($task->mode) {
case 'daily':
$dates[] = ValidateDate::get(Grap::$folder);
break;
case 'last3days':
case 'range':
switch ($task_id) {
case 2:
$from = Carbon::now()->subDays(3);
$to = Carbon::now()->subDays(1);
break;
default:
$from = ValidateDate::get($task->day_from);
$from = Carbon::createFromDate($from);
$to = ValidateDate::get($task->day_to);
$to = Carbon::createFromDate($to);
break;
}
$lengthdates = $from->diffInDays($to);
if ($lengthdates < 1) {
Notice::note('start must be before end', 'r', 1);
}
if ($restart) {
// get all days
while ($from <= $to) {
$dates[] = $from->format('Y-m-d');
$from->addDay();
}
} else {
// remove days done
while ($from <= $to) {
$res = SofaScoreTaskDay::firstOrNew(['grapper_id' => (int) $task_id, 'day' => $from->format('Y-m-d')]);
if (! $res->done) {
$dates[] = $from->format('Y-m-d');
}
$from->addDay();
}
shuffle($dates);
}
break;
}
if (! $dates) {
Notice::note('NO DATES OR ALL GRAPPED', 'br', 1);
}
if ($debug) {
Notice::note($dates, 'b');
}
// remove when element in array is double (day and slug)
$dates = array_unique($dates, SORT_REGULAR);
return $dates;
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Nuh;
use App\Models\SofaScoreTournament;
use App\Utilities\Notice;
class LoadTournaments
{
public static function load()
{
$sport_id = Nuh::$options['sport_id'];
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('LoadTournaments, sport: ' . $sport_id);
}
$tornaments = SofaScoreTournament::select('name', 'tournament_id')->where('sport_id', $sport_id)->where('enabled', 1)->get();
if (! $tornaments) {
Notice::note('no tornaments active for task', 'r', 1);
}
return $tornaments;
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Grap;
class MoveToArchive
{
public static function move(int $task_id)
{
$files = ReadDir::get_tree(Grap::$storage);
$filtered_files = FileType::filter($files, ['xlsx', 'json']);
foreach ($filtered_files as $file) {
switch ($task_id) {
case 1:
$nfile = \str_replace('/daily/', '/daily_archiv/', $file);
break;
}
rename($file, $nfile);
dd($file, $nfile);
}
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
class ReadDir
{
public static function get_tree(string $dir, &$results = array())
{
$files = scandir($dir);
foreach ($files as $value) {
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (!is_dir($path)) {
$results[] = $path;
} else if ($value != "." && $value != "..") {
self::get_tree($path, $results);
$results[] = $path;
}
}
return $results;
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Grap;
use App\Utilities\Notice;
use Illuminate\Support\Facades\Storage;
class RemoveDir
{
public static function remove(): void
{
$debug = Grap::$options['d'];
// Deletes the directory and everything inside it relative to the disk root
Storage::deleteDirectory(Grap::$storage . '/' . Grap::$folder);
if ($debug) {
Notice::note('Directory: ' . Grap::$storage . '/' . Grap::$folder . ' removed', 'p');
}
}
}
@@ -0,0 +1,71 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Grap;
use App\Models\SofaScoreTask;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class SetStorage
{
public static function set(int $task_id)
{
$debug = Grap::$options['d'];
$force = Grap::$options['f'];
$folder = Grap::$options['folder'] ?? '';
$date = Grap::$options['date'] ?? '';
$day = Grap::$options['day'] ?? 1;
// must be connectet to task for activated ligas
$task = SofaScoreTask::where('id', $task_id)->first();
$sofascore_data = storage_path('sofascore_data') . '/';
if ($task) {
$storage_name = Strings::clean($task->name);
switch ($task->id) {
case 1:
Grap::$storage = $sofascore_data . $storage_name;
Grap::$folder = Carbon::now()->subDays($day)->format('Y-m-d');
Grap::$excel = Grap::$storage . '/' . Grap::$folder;
break;
case 2:
Grap::$storage = $sofascore_data . $storage_name;
Grap::$folder = $date;
Grap::$excel = $sofascore_data . $storage_name . '/' . $date;
break;
case 3:
Grap::$storage = $sofascore_data . 'range/' . $storage_name;
Grap::$folder = $storage_name;
Grap::$excel = $sofascore_data . 'range/' . $storage_name;
break;
case 4:
Grap::$storage = $sofascore_data . $storage_name;
Grap::$folder = 'rosa-' . Carbon::now()->format('Y-m-d');
Grap::$excel = Grap::$storage . '/rosa-' . Carbon::now()->format('Y-m-d');
break;
case 5:
Grap::$storage = $sofascore_data . 'excel';
Grap::$folder = $folder;
Grap::$excel = $sofascore_data . 'excel/' . $storage_name;
break;
}
} elseif ($folder) {
Grap::$storage = $sofascore_data;
Grap::$folder = $folder;
}
if ($debug) {
Notice::note(Grap::$storage, 'g');
Notice::note(Grap::$folder, 'g');
if (!$force) {
sleep(4);
}
}
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
class Sleeper
{
public static function rand($speed = false)
{
switch ($speed) {
case 1:
// 5 -10 sec
$sleep = rand(5000000, 10000000);
break;
case 2:
// 10 - 20 sec
$sleep = rand(10000000, 20000000);
break;
default:
// 1 -1.5 sec
$sleep = rand(100000, 150000);
break;
}
usleep($sleep);
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
class Strings
{
public static function clean(string $string)
{
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
$string = strtolower($string);
return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class ValidateDate
{
public static function get(string $date)
{
if (Carbon::createFromDate($date) !== false) {
return $date;
} else {
Notice::note('Wrong date format', 'r', 1);
}
}
}
@@ -0,0 +1,36 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Helper;
use App\Console\Commands\Grap;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ZipArchive;
class ZipFolder
{
public static function create()
{
$zip = new ZipArchive;
if ($zip->open(Grap::$zipfile, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
if (is_dir(Grap::$storage)) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Grap::$storage));
foreach ($files as $file) {
if (! $file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen(Grap::$storage) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
}
} else {
return response()->json(['error' => 'Failed to create ZIP archive'], 500);
}
}
}
@@ -0,0 +1,80 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grap;
use App\Console\Commands\Grapper\Sofascore\Helper\FileType;
use App\Console\Commands\Grapper\Sofascore\Helper\ReadDir;
use App\Utilities\Notice;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class MakeExcel
{
public static $max = 2000;
public static function create(string $what = '')
{
ini_set('memory_limit', -1);
$debug = Grap::$options['d'] ?? 0;
if ($debug) {
Notice::note("Make Excel");
}
if ($what == 'day') {
$files = ReadDir::get_tree(Grap::$storage . '/' . Grap::$folder);
} else {
$files = ReadDir::get_tree(Grap::$storage);
}
$files = array_chunk(FileType::filter($files), self::$max);
foreach ($files as $key => $value) {
$has = count($value);
if (! $key && $has < self::$max) {
$from = 1;
$to = $has;
} elseif (! $key) {
$from = 1;
$key++;
$to = $key * self::$max;
} elseif ($has == self::$max) {
$from = $key * self::$max + 1;
$key++;
$to = $key * self::$max;
} else {
$from = $key * self::$max + 1;
$to = $key * self::$max + $has;
}
$spreadsheet = new Spreadsheet;
$spreadsheet->getProperties()->setTitle(Grap::$excel . '_' . $from . '-' . $to);
$activeWorksheet = $spreadsheet->getActiveSheet();
$column = 1;
foreach ($value as $file) {
$data = file_get_contents($file);
$data = json_decode($data, true);
$json_string = json_encode($data, JSON_PRETTY_PRINT);
$arr = explode(PHP_EOL, $json_string);
$row = 0;
foreach ($arr as $string) {
$row++;
$replacedString = preg_replace("/\\\\u([0-9abcdef]{4})/", "&#x$1;", $string);
$utf8string = mb_convert_encoding($replacedString, 'UTF-8', 'HTML-ENTITIES');
$activeWorksheet->setCellValue([$column, $row], $utf8string);
}
$column++;
}
$spreadsheet->setActiveSheetIndex(0);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save(Grap::$excel . '_' . $from . '-' . $to . '.xlsx');
}
}
}
@@ -0,0 +1,13 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grapper\Sofascore;
class Player
{
public static function call()
{
// https://www.sofascore.com/api/v1/player/824509
}
}
@@ -0,0 +1,71 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grap;
use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa;
use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper;
use App\Console\Commands\Grapper\Sofascore\Helper\Strings;
use App\Models\SofaScoreRosa;
use App\Utilities\Notice;
use Illuminate\Support\Facades\File;
class Rose
{
public static function run()
{
$debug = Grap::$options['d'] ?? 0;
$restart = Grap::$options['r'] ?? 0;
if ($debug && ! $restart) {
Notice::note('RESTART ?', 'bb');
sleep(5);
}
File::makeDirectory(Grap::$storage.'/'.Grap::$folder, 0775, true, true);
if ($restart) {
SofaScoreRosa::query()->update(['grapped' => 0]);
if ($debug) {
Notice::note('reset all grapped to 0', 'r', 1);
}
} else {
if ($debug) {
Notice::note('continuing grapping', 'bg');
}
}
$res = SofaScoreRosa::where('is_active', 1)->where('grapped', 0)->get();
$all = $res->count();
if ($debug) {
Notice::note("total $all", 'br');
}
foreach ($res as $key => $value) {
if ($debug) {
$key++;
echo "\n$key/$all\n";
}
$url = Grap::$options['base_url'].'api/v1/team/'.$value->ss_team_id.'/players';
$data = CurlSofa::load($url);
$data['ss_team_id'] = $value->ss_team_id;
$data['ss_team_name'] = $value->ss_team_name;
/*********************************
* add team to folder
*********************************/
File::put(Grap::$storage.'/'.Grap::$folder.'/'.Strings::clean($value->ss_team_name).'.json', json_encode($data));
SofaScoreRosa::where('id', $value->id)->update(['grapped' => 1]);
Sleeper::rand(rand(0, 3));
}
}
}
@@ -0,0 +1,74 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grap;
use App\Console\Commands\Grapper\Sofascore\Helper\FileType;
use App\Console\Commands\Grapper\Sofascore\Helper\ReadDir;
use App\Mail\SofaScoreDataMail;
use App\Models\SofaScoreEventGrapped;
use App\Models\SofaScoreTask;
use App\Utilities\Notice;
use Illuminate\Support\Facades\Mail;
class SendMail
{
public static function run(int $task_id)
{
$debug = Grap::$options['d'] ?? 0;
if ($debug) {
Notice::note('Send Mail', 'bb');
}
$task = SofaScoreTask::where('id', $task_id)->first();
$files = ReadDir::get_tree(Grap::$storage);
$sendfiles = FileType::filter($files, ['xlsx']);
$header = self::createHeader($task);
$table = self::createTable($task);
Mail::to('hermann.telser@gmail.com')
->cc('ubaldo.perrucci@gmail.com')
->send(
new SofaScoreDataMail($header, $table, $sendfiles)
);
if ($debug) {
Notice::note("Mail Send", 'bg');
}
}
public static function createTable(SofaScoreTask $task)
{
$res = SofaScoreEventGrapped::where('grapper_id', $task->id)->get();
$table = '';
foreach ($res as $value) {
$table .= '|' . $value->liga . '|' . $value->name . '|' . $value->starttime . '|
';
}
return $table;
}
public static function createHeader(SofaScoreTask $task)
{
switch ($task->id) {
case 2:
$text = $task->name . ' - ' . $task->day_from;
break;
case 3:
$text = $task->name . ' - ' . $task->day_from . ' - ' . $task->day_to;
break;
default:
$text = $task->name . ' - ' . Grap::$folder;
break;
}
return $text;
}
}
@@ -0,0 +1,79 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grap;
use App\Models\SofaScoreRosa;
use App\Models\SofaScoreTask;
use App\Models\SofaScoreTaskTournament;
use App\Models\SofaScoreTournament;
use App\Utilities\Notice;
use Illuminate\Support\Facades\DB;
class SettingsToLocal
{
public static function run()
{
$debug = Grap::$options['d'] ?? 0;
if ($debug) {
Notice::note('⚽ settings to local');
Notice::note('⚽ close all vpn');
}
exec('killall ssh');
if ($debug) {
Notice::note('⚽ open vpn');
}
exec('ssh -f -N -L 13306:127.0.0.1:3306 -p 58371 root@162.55.242.190');
/**
* SofaScoreRosa
*/
if ($debug) {
Notice::note('SofaScoreRosa', 'g');
}
SofaScoreRosa::truncate();
$rows = DB::connection('remote_mariadb')->table('sofa_score_rosas')->get();
foreach ($rows as $row) {
SofaScoreRosa::insert((array) $row);
}
/**
* SofaScoreTask
*/
if ($debug) {
Notice::note('SofaScoreTask', 'g');
}
SofaScoreTask::truncate();
$rows = DB::connection('remote_mariadb')->table('sofa_score_tasks')->get();
foreach ($rows as $row) {
SofaScoreTask::insert((array) $row);
}
/**
* SofaScoreTaskTournament
*/
if ($debug) {
Notice::note('SofaScoreTaskTournament', 'g');
}
SofaScoreTaskTournament::truncate();
$rows = DB::connection('remote_mariadb')->table('sofa_score_task_tournaments')->get();
foreach ($rows as $row) {
SofaScoreTaskTournament::insert((array) $row);
}
/**
* SofaScoreTournament
*/
if ($debug) {
Notice::note('SofaScoreTournament', 'g');
}
SofaScoreTournament::truncate();
$rows = DB::connection('remote_mariadb')->table('sofa_score_tournaments')->get();
foreach ($rows as $row) {
SofaScoreTournament::insert((array) $row);
}
if ($debug) {
Notice::note('⚽ close all vpn');
}
exec('killall ssh');
}
}
@@ -0,0 +1,40 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Nuh;
use App\Models\SofaScoreRosaTournament;
use App\Utilities\Notice;
use Illuminate\Support\Facades\DB;
class SettingsToProduction
{
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('Settings To Production', 'bb');
}
if ($debug) {
Notice::note('SofaScoreRosaTournament', 'g');
}
DB::connection('remote_mariadb')->table('sofa_score_rosa_tournaments')->truncate();
$rows = SofaScoreRosaTournament::get();
foreach ($rows as $row) {
DB::connection('remote_mariadb')->table('sofa_score_rosa_tournaments')->insert([
"ss_team_id" => $row->ss_team_id,
"ss_tournament_id" => $row->ss_tournament_id,
"disabled" => $row->disabled,
"grapped" => $row->grapped,
"created_at" => $row->created_at,
"updated_at" => $row->updated_at,
]);
}
}
}
@@ -0,0 +1,66 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grap;
use App\Console\Commands\Grapper\Sofascore\Helper\ReadDir;
use App\Console\Commands\Grapper\Sofascore\Helper\Strings;
use App\Models\SofaScoreCategory;
use App\Models\SofaScoreRosa;
use App\Models\SofaScoreTask;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
use App\Utilities\Notice;
class SqlMover
{
public static function run()
{
Notice::note('SqlMover', 'b');
// $task = SofaScoreTask::where('id', 3)->first();
// $folder = Strings::clean($task->name) . '-' . $task->day_from . '-' . $task->day_to;
// $sofascore_data = storage_path('sofascore_data') . '/';
// $files = ReadDir::get_tree($sofascore_data . $folder);
// dd($files);
$file = file_get_contents(__dir__ . '/SqlMover/country.txt');
$data = explode(PHP_EOL, $file);
foreach ($data as $key => $value) {
if ($key) {
$row = explode(',', $value);
$country_id = $row[0];
$flag = $row[2];
$season_mode = $row[6];
SofaScoreCategory::where('country_id', $country_id)->update([
'season_mode' => $season_mode,
'flag' => $flag,
'in_soccer' => 1,
]);
}
}
Notice::note('DONE', 'r', 1);
// Notice::note('StatistikoPlayer', 'b');
// $res = StatistikoEvent::pluck('match_id');
// foreach ($res as $match_id) {
// $has = StatistikoPlayer::where('match_id', (int) $match_id)->first();
// if (!$has)
// echo $match_id . "\n";
// }
// Notice::note('StatistikoEvent', 'b');
// $res = StatistikoPlayer::get();
// foreach ($res as $pl) {
// $has = StatistikoEvent::where('match_id', (int) $pl->match_id)->first();
// if (!$has) {
// echo $match_id . "\n";
// }
// }
Notice::note('done', 'bb', 1);
}
}
Loaded 100 of 1209 files, more files were not shown because too many files have changed in this diff. Show more