wip matches

This commit is contained in:
salam committed 2025-08-27 12:51:03 +02:00
1 parent adb15e701b
commit 7116d3c576
33 files changed
+379 -176

No files matched your search

+140
View File
@@ -0,0 +1,140 @@
<?php
namespace App\Console\Commands;
use App\Utilities\Notice;
class Curl
{
public static $storage_file;
public static function load($url)
{
self::$storage_file = app_path().'/Utilities/TestFileStorage/latest.json';
$debug = NuhBash::$options['debug'] ?? 0;
$save_to_storage = NuhBash::$options['s'] ?? 0;
$load_form_storage = NuhBash::$options['l'] ?? 0;
if ($debug) {
Notice::note($url, 'g');
}
if ($load_form_storage) {
$file = file_get_contents(self::$storage_file);
if ($debug) {
Notice::note('data from storage', 'b');
}
return json_decode($file, true);
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$data = curl_exec($ch);
$curl_errorno = curl_errno($ch);
if ($curl_errorno) {
Notice::note('curl_errorno: '.self::curlerrorcode($curl_errorno));
}
curl_close($ch);
if ($save_to_storage) {
Notice::note('data saved to local storage', 'b');
file_put_contents(self::$storage_file, $data);
}
return json_decode($data, true);
}
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',
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];
}
}
-36
View File
@@ -1,36 +0,0 @@
<?php
namespace App\Console\Commands\Grapper;
use App\Utilities\Notice;
class Helper
{
/**
* Create a new class instance.
*/
public static function get_auth_string()
{
if (Grapper::$options['provider_id'] == 1) {
// txodds soccer
Grapper::$auth = 'ident=betaid1&passwd=Dy59vpRC';
Grapper::$domain = 'https://xml2.txodds.com/';
} elseif (Grapper::$options['provider_id'] == 3) {
// txodds others
Grapper::$auth = 'ident=betaid2&passwd=Dy59vpRC';
Grapper::$domain = 'https://xml2.txodds.com/';
} else {
Notice::note('error txodds provider', 'r', 1);
}
}
public static function margin($arr)
{
$r = 0;
foreach ($arr as $key => $value) {
$r += 100 / $value;
}
return round($r, 3);
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Console\Commands\Grapper\TxOdds;
use App\Models\Element;
class TxElement
{
public static function find($element, $sport_id)
{
// dd($element);
$txodds_id = array_column($element, 'id');
$element = Element::firstOrCreate([
'name' => (string) $element['@text'],
'sport_id' => $sport_id,
'txodds_id' => (int) $txodds_id[0],
]);
return $element->id;
}
}
@@ -0,0 +1,32 @@
<?php
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\NuhBash;
use App\Models\Country;
use App\Models\Liga;
class TxLigas
{
public static function find($group)
{
$debug = NuhBash::$options['debug'] ?? 0;
$cgid = array_column($group, 'cgid');
$cnid = array_column($group, 'cnid');
$spid = array_column($group, 'spid');
$cname = array_column($group, 'cname');
$country_id = Country::where('txid', $cnid)->value('id');
$liga = Liga::firstOrCreate([
'name' => (string) $cname[0],
'sport_id' => (int) $spid[0],
'country_id' => $country_id,
'txodds_id' => (int) $cgid[0],
]);
return $liga->id;
}
}
@@ -0,0 +1,45 @@
<?php
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\Curl;
use App\Console\Commands\NuhBash;
use App\Models\Event;
class FixturesSoccer
{
public static function call()
{
$debug = NuhBash::$options['debug'] ?? 0;
for ($i = 0; $i < 30; $i++) {
$str1 = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + $i, date('Y')));
$str2 = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 1 + $i, date('Y')));
$url = 'https://xml2.txodds.com/feed/result/xml.php?ident=betaid1&passwd='.config('nuh.txodds_token')."&date=$str1,$str2&json=2";
$data = Curl::load($url, $debug);
foreach ($data['match'] as $row) {
$txodds_id = array_column($row, 'id');
$spid = array_column($row['group'], 'spid');
$liga_id = TxLigas::find($row['group']);
$home_id = TxElement::find($row['hteam'], 1);
$away_id = TxElement::find($row['ateam'], 1);
$event = Event::firstOrCreate([
'starttime' => date('Y-m-d H:i:s', strtotime($row['time'])),
'sport_id' => (int) $spid[0],
'provider_id' => 1,
'txodds_id' => (int) $txodds_id,
'liga_id' => $liga_id,
'home_id' => $home_id,
'away_id' => $away_id,
]);
dd($event);
}
}
}
}
@@ -1,34 +1,32 @@
<?php
namespace App\Console\Commands\Grapper\TxOdds;
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\Grapper;
use App\Console\Commands\Grapper\TxOdds\FixturesSoccer;
use App\Console\Commands\NuhBash;
class TxOdds
class TxSwitch
{
/**
* https://docs.guzzlephp.org/en/latest/
*/
public static function switch()
{
switch (Grapper::$options['option_id']) {
switch (NuhBash::$options['id']) {
case 1:
// Leages
FixturesSoccer::call();
break;
case 2:
Events::grap();
break;
case 3:
// Flags
break;
case 4:
Odds::grap();
break;
case 5:
Countries::grap();
break;
default:
Note::notice('Provider not defined', 'r', 1);
Note::notice('wrong process id for txodds', 'r', 1);
break;
}
}
+26 -16
View File
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
use App\Console\Commands\Grapper\TxOdds\TxOdds;
use App\Console\Commands\Grapper\TxSwitch;
use App\Models\Supervisor;
use App\Utilities\Notice;
use App\Utilities\Supervisorctl;
@@ -26,7 +26,7 @@ class NuhBash extends Command
public static $auth = '';
protected $signature = 'nuh {process=help} {eventid=0} {--d} {--f} {--a} {--p} {--w}';
protected $signature = 'nuh {process=help} {eventid=0} {--d} {--f} {--a} {--p} {--w} {--s} {--l}';
protected $description = 'NuhBash';
@@ -38,11 +38,12 @@ class NuhBash extends Command
self::$options['event_id'] = $this->argument('eventid');
if ($this->argument('process') == 'help') {
$txt = 'List of parameters'.PHP_EOL;
$txt = PHP_EOL;
$txt .= 'List of parameters'.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL;
$txt .= 'process [id] (required)'.PHP_EOL;
$txt .= 'eventid [id] (optional)'.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL.PHP_EOL;
$txt .= 'List of options'.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL;
$txt .= '--d debug'.PHP_EOL;
@@ -50,7 +51,9 @@ class NuhBash extends Command
$txt .= '--a reload all'.PHP_EOL;
$txt .= '--w reload one week'.PHP_EOL;
$txt .= '--p print odds'.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL;
$txt .= '--s store grapped file '.PHP_EOL;
$txt .= '--l load latest grapped file '.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL.PHP_EOL;
$txt .= 'List of supervisors'.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL;
$tmp = Supervisor::all();
@@ -62,18 +65,25 @@ class NuhBash extends Command
Supervisorctl::start(self::$options);
Helper::get_auth_string();
switch (self::$options['type']) {
case 'Grapper':
switch (self::$options['provider_id']) {
case 1:
TxSwitch::switch();
case 2:
// betsapi
break;
case 3:
// direct
break;
default:
Note::notice('Provider not defined', 'r', 1);
break;
}
break;
switch (self::$options['provider_id']) {
case 1:
case 2:
TxOdds::switch();
break;
case 3:
// betsapi
break;
default:
Note::notice('Provider not defined', 'r', 1);
case 'Comparatore':
// code...
break;
}