This commit is contained in:
salam committed 2026-06-08 15:12:27 +02:00
1 parent 336af556a1
commit 8578ec96bb
6 files changed
+54 -71

No files matched your search

+4 -7
View File
@@ -17,7 +17,7 @@ class Curl
if ($debug) {
if ($proxy) {
Notice::note($url.PHP_EOL.Nuh::$options['proxy'], 'b');
Notice::note($url . PHP_EOL . Nuh::$options['proxy'], 'b');
} else {
Notice::note($url, 'g');
}
@@ -27,7 +27,7 @@ class Curl
if ($debug) {
Notice::note('data read localy', 'g');
}
$filename = app_path().self::$testfiles.strtolower(str_replace(' ', '_', Nuh::$options['name'])).'.json';
$filename = app_path() . self::$testfiles . strtolower(str_replace(' ', '_', Nuh::$options['name'])) . '.json';
$file = file_get_contents($filename);
@@ -37,7 +37,7 @@ class Curl
$file = self::fetch_data_with_retries($url, $_config);
if ($save) {
$filename = app_path().self::$testfiles.strtolower(str_replace(' ', '_', Nuh::$options['name'])).'.json';
$filename = app_path() . self::$testfiles . strtolower(str_replace(' ', '_', Nuh::$options['name'])) . '.json';
file_put_contents($filename, $file);
@@ -125,20 +125,17 @@ class Curl
$attempt++;
$curl_errorno = curl_errno($ch);
if ($debug && $curl_errorno) {
Notice::note('curl_errorno: '.self::curlerrorcode($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 {
curl_close($ch);
return $response;
}
}
echo "All attempts failed.\n";
curl_close($ch);
return null; // Return null if all retries fail
}
@@ -32,7 +32,11 @@ class Events
// to grap event id
// https://www.sofascore.com/api/v1/unique-tournament/2480/scheduled-events/2022-05-19
// https://www.sofascore.com/api/v1/unique-tournament/2480/scheduled-events/2026-05-31
// per event
// https://www.sofascore.com/api/v1/event/16198485/statistics
// https://www.sofascore.com/api/v1/event/16198485/odds/1/all
$years_back = 7;
$dates = Carbon::now()->subYears($years_back);
@@ -18,24 +18,32 @@ class Tournament
{
public static function load()
{
$days = 1;
$debug = Nuh::$options['d'] ?? 0;
$force = Nuh::$options['f'] ?? 0;
$sport_id = Nuh::$options['sport_id'];
$sport = Sport::where('id', $sport_id)->first();
$dates = Carbon::now();
// start yesterday
$grapping_date = Carbon::now()->subDay();
while ($dates >= Carbon::now()->subYears($sport->ss_grap_years)) {
$days++;
$days_back = Carbon::now()->subDays($days);
while ($grapping_date >= $days_back) {
$tournaments_counter = 0;
$day = $dates->format('Y-m-d');
$day = $grapping_date->format('Y-m-d');
/**
* grap only one time/sport check
*/
if (! SofaScoreDay::where('day', $day)->where($sport->ss_slug, 1)->first()) {
if ($force || ! SofaScoreDay::where('day', $day)->where($sport->ss_slug, 1)->first()) {
if ($debug) {
Notice::note('Grapping Sport: ' . Nuh::$options['sport'] . ' Day: ' . $day, 'g');
@@ -168,7 +176,7 @@ class Tournament
Notice::note('Having Sport: ' . Nuh::$options['sport'] . ' Day: ' . $day, 'b');
}
}
$dates->subDay();
$grapping_date->subDay();
}
}
}
+4 -6
View File
@@ -16,14 +16,14 @@ class Xml
$save = Nuh::$options['s'] ?? 0;
$read = Nuh::$options['r'] ?? 0;
$filename = app_path().'/Console/Commands/TestFiles/'.strtolower(str_replace(' ', '_', Nuh::$options['name'])).'.xml';
$filename = app_path() . '/Console/Commands/TestFiles/' . strtolower(str_replace(' ', '_', Nuh::$options['name'])) . '.xml';
if ($debug) {
Notice::note("Loading URL\n".$url);
Notice::note("Loading URL\n" . $url);
}
if ($save || $read) {
Notice::note("FILE NAME\n".$filename);
Notice::note("FILE NAME\n" . $filename);
}
if ($read) {
@@ -96,16 +96,14 @@ class Xml
echo "Attempt $attempt failed. Retrying...\n";
sleep(2); // Optional: Sleep between retries
} else {
curl_close($ch);
if (mb_substr($response, 0, 1) != '<') {
Log::debug('INVALID XML '.$url.'----'.$response);
Log::debug('INVALID XML ' . $url . '----' . $response);
} else {
return new SimpleXMLElement($response);
}
}
}
echo "All attempts failed.\n";
curl_close($ch);
return null; // Return null if all retries fail
}