changes to grapper wip
This commit is contained in:
1 parent
361e5ed3ed
commit
9214da8a15
9 files changed
+445
-201
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands\Grapper;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore\Events;
|
||||
use App\Console\Commands\Grapper\Sofascore\EventsDatabase;
|
||||
use App\Console\Commands\Grapper\Sofascore\Special;
|
||||
use App\Console\Commands\Grapper\Sofascore\Tournament;
|
||||
use App\Console\Commands\Nuh;
|
||||
@@ -17,8 +18,11 @@ use Illuminate\Support\Carbon;
|
||||
class Sofascore
|
||||
{
|
||||
public static $auth_header = [];
|
||||
|
||||
public static $base_url = '';
|
||||
|
||||
public static $_days = [];
|
||||
|
||||
public static $sport = [1];
|
||||
|
||||
public static function switch()
|
||||
@@ -35,13 +39,14 @@ class Sofascore
|
||||
|
||||
if (Nuh::$options['t']) {
|
||||
self::$_days[] = Carbon::now()->format('Y-m-d');
|
||||
} else if (Nuh::$options['day']) {
|
||||
if (self::validateDate(Nuh::$options['day'])) {
|
||||
self::$_days[] = Nuh::$options['day'];
|
||||
} elseif (Nuh::$options['day']) {
|
||||
$day = self::validateDate(Nuh::$options['day']);
|
||||
if ($day) {
|
||||
self::$_days[] = $day;
|
||||
} else {
|
||||
Notice::note('date not valid ' . Nuh::$options['day'], 'r', 1);
|
||||
Notice::note('date not valid '.Nuh::$options['day'], 'r', 1);
|
||||
}
|
||||
} else if (Nuh::$options['days']) {
|
||||
} elseif (Nuh::$options['days']) {
|
||||
$to = Carbon::now()->subDays(Nuh::$options['days']);
|
||||
$from = Carbon::now()->subDay();
|
||||
while ($from >= $to) {
|
||||
@@ -51,9 +56,9 @@ class Sofascore
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
Notice::note(Nuh::$options['sport'] . ' ' . Nuh::$options['name'], 'bb');
|
||||
Notice::note(Nuh::$options['sport'].' '.Nuh::$options['name'], 'bb');
|
||||
}
|
||||
|
||||
|
||||
switch (Nuh::$options['name']) {
|
||||
case 'TOURNAMENTS':
|
||||
Tournament::load();
|
||||
@@ -61,6 +66,9 @@ class Sofascore
|
||||
case 'EVENTS':
|
||||
Events::load();
|
||||
break;
|
||||
case 'EVENTSDB':
|
||||
EventsDatabase::load();
|
||||
break;
|
||||
case 'SPECIAL':
|
||||
Special::load();
|
||||
break;
|
||||
@@ -73,7 +81,13 @@ class Sofascore
|
||||
|
||||
public static function validateDate($date, $format = 'Y-m-d')
|
||||
{
|
||||
if (is_numeric($date)) {
|
||||
$date = date('Y').'-'.date('m').'-'.$date;
|
||||
}
|
||||
$d = DateTime::createFromFormat($format, $date);
|
||||
return $d && $d->format($format) == $date;
|
||||
|
||||
if ($d && $d->format($format) == $date) {
|
||||
return $d->format($format);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
/grapped
|
||||
/worldcup-teams
|
||||
/grapped
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore;
|
||||
use App\Console\Commands\Nuh;
|
||||
use App\Models\SofaScoreDayTournament;
|
||||
use App\Utilities\Notice;
|
||||
@@ -18,20 +17,20 @@ class Events
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
$print = Nuh::$options['p'] ?? 0;
|
||||
$sport_id = Nuh::$options['sport_id'];
|
||||
|
||||
$dback = Nuh::$options['days'] ?? 1;
|
||||
|
||||
$singleday = Nuh::$options['day'] ?? 0;
|
||||
if($singleday){
|
||||
if ($singleday) {
|
||||
$dback = 1;
|
||||
}
|
||||
|
||||
if($print){
|
||||
if ($print) {
|
||||
for ($i = 1; $i <= $dback; $i++) {
|
||||
$day = Carbon::now()->subDays($i)->format('Y-m-d');
|
||||
if ($debug) {
|
||||
Notice::note($day, 'p');
|
||||
}
|
||||
if(Nuh::$options['groups']){
|
||||
if (Nuh::$options['groups']) {
|
||||
$tornaments = explode(',', Nuh::$options['groups']) ?? 0;
|
||||
$ss_days = SofaScoreDayTournament::with('tournament')
|
||||
->when($tornaments, function ($query) use ($tornaments) {
|
||||
@@ -52,38 +51,22 @@ class Events
|
||||
* finland veikkaus => 41
|
||||
*/
|
||||
$tornaments = explode(',', Nuh::$options['groups']) ?? 0;
|
||||
|
||||
|
||||
// for ($i = 1; $i <= $dback; $i++) {
|
||||
// // remove one day to start yesterday
|
||||
// $day = Carbon::now()->subDays($i)->format('Y-m-d');
|
||||
// if ($debug) {
|
||||
// Notice::note($day, 'p');
|
||||
// }
|
||||
// $ss_days = SofaScoreDayTournament::with('tournament')
|
||||
// ->when($tornaments, function ($query) use ($tornaments) {
|
||||
// return $query->whereIn('tournament_id', $tornaments);
|
||||
// })
|
||||
// ->whereHas('tournament', function ($query) use ($sport_id) {
|
||||
// $query->where('sport_id', $sport_id);
|
||||
// })
|
||||
// ->where('day', $day)->get();
|
||||
// foreach ($ss_days as $ss_day) {
|
||||
// $sofa_score_categorie_id = $ss_day->tournament->sofa_score_categorie_id;
|
||||
// // https://www.sofascore.com/api/v1/unique-tournament/16/scheduled-events/2026-06-19
|
||||
// $url = Nuh::$options['base_url'] . "api/v1/category/$sofa_score_categorie_id/scheduled-events/$day";
|
||||
// Notice::note($url, 'p');
|
||||
// }
|
||||
// }
|
||||
// exit;
|
||||
if (array_sum($tornaments)) {
|
||||
if ($debug) {
|
||||
Notice::note('groups and day(s) used from comandline', 'p');
|
||||
}
|
||||
if (! Nuh::$options['days'] or ! Nuh::$options['day']) {
|
||||
Notice::note('no day(s) option in comandline (--day=1)', 'r', 1);
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= $dback; $i++) {
|
||||
|
||||
|
||||
// remove one day to start yesterday
|
||||
$day = Carbon::now()->subDays($i)->format('Y-m-d');
|
||||
|
||||
// call for spezific day
|
||||
if($singleday){
|
||||
if ($singleday) {
|
||||
$dback = 1;
|
||||
$day = $singleday;
|
||||
}
|
||||
@@ -102,13 +85,14 @@ class Events
|
||||
->where('day', $day)->get();
|
||||
|
||||
foreach ($ss_days as $ss_day) {
|
||||
|
||||
|
||||
$sofa_score_categorie_id = $ss_day->tournament->sofa_score_categorie_id;
|
||||
|
||||
$tournament_id = $ss_day->tournament_id;
|
||||
|
||||
// $url = Nuh::$options['base_url'] . "api/v1/category/$sofa_score_categorie_id/scheduled-events/$day";
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/unique-tournament/$tournament_id/scheduled-events/$day";
|
||||
$url = Nuh::$options['base_url']."api/v1/unique-tournament/$tournament_id/scheduled-events/$day";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
@@ -120,13 +104,13 @@ class Events
|
||||
|
||||
Nuh::$options['s'] = 0;
|
||||
|
||||
Nuh::$options['r'] = 0;
|
||||
Nuh::$options['r'] = 0;
|
||||
|
||||
foreach ($data['events'] as $event) {
|
||||
|
||||
Notice::note($event['season']['name'].' '. $ss_day->day, 'bb');
|
||||
Notice::note($event['season']['name'].' '.$ss_day->day, 'bb');
|
||||
|
||||
$folder = app_path() . self::$storage_path . $ss_day->day . '/' . $event['tournament']['slug'] . '/' . $event['slug'];
|
||||
$folder = app_path().self::$storage_path.$ss_day->day.'/'.$event['tournament']['slug'].'/'.$event['slug'];
|
||||
|
||||
File::makeDirectory($folder, 0775, true, true);
|
||||
|
||||
@@ -134,7 +118,7 @@ class Events
|
||||
* EVENT event
|
||||
*********************************/
|
||||
|
||||
File::put($folder . '/event.json', json_encode($event));
|
||||
File::put($folder.'/event.json', json_encode($event));
|
||||
|
||||
/*********************************
|
||||
* EVENT statistics
|
||||
@@ -142,7 +126,7 @@ class Events
|
||||
|
||||
$event_id = $event['id'];
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/statistics";
|
||||
$url = Nuh::$options['base_url']."api/v1/event/$event_id/statistics";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
@@ -152,7 +136,7 @@ class Events
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder . '/statistics.json', json_encode($data));
|
||||
File::put($folder.'/statistics.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
@@ -160,7 +144,7 @@ class Events
|
||||
|
||||
$event_id = $event['id'];
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/lineups";
|
||||
$url = Nuh::$options['base_url']."api/v1/event/$event_id/lineups";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
@@ -170,8 +154,7 @@ class Events
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder . '/lineups.json', json_encode($data));
|
||||
|
||||
File::put($folder.'/lineups.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
@@ -179,7 +162,7 @@ class Events
|
||||
|
||||
$event_id = $event['id'];
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/odds/1/all";
|
||||
$url = Nuh::$options['base_url']."api/v1/event/$event_id/odds/1/all";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
@@ -189,7 +172,7 @@ class Events
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder . '/odds.json', json_encode($data));
|
||||
File::put($folder.'/odds.json', json_encode($data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore;
|
||||
|
||||
use App\Console\Commands\Nuh;
|
||||
use App\Models\SofaScoreDay;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class EventsDatabase
|
||||
{
|
||||
public static $storage_path = '/Console/Commands/Grapper/Sofascore/grapped/';
|
||||
|
||||
public static function load()
|
||||
{
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
$print = Nuh::$options['p'] ?? 0;
|
||||
$sport_id = Nuh::$options['sport_id'];
|
||||
|
||||
$days = SofaScoreDay::where('sport_id', $sport_id)->where('enabled', 1)->pluck('day')->toArray();
|
||||
$tornaments = SofaScoreTournament::where('sport_id', $sport_id)->where('enabled', 1)->get();
|
||||
|
||||
if (! $days) {
|
||||
Notice::note('No days active in DB', 'r', 1);
|
||||
}
|
||||
if (! $tornaments) {
|
||||
Notice::note('No tornaments active in DB', 'r', 1);
|
||||
}
|
||||
|
||||
if ($print) {
|
||||
dd($days, $tornaments);
|
||||
}
|
||||
|
||||
foreach ($days as $day) {
|
||||
|
||||
if ($debug) {
|
||||
Notice::note($day, 'b');
|
||||
}
|
||||
|
||||
foreach ($tornaments as $tournament) {
|
||||
|
||||
if ($debug) {
|
||||
Notice::note($tournament->name, 'b');
|
||||
}
|
||||
|
||||
$url = Nuh::$options['base_url']."api/v1/unique-tournament/$tournament->tournament_id/scheduled-events/$day";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
|
||||
if ($debug) {
|
||||
Notice::note("Sleep $rand msec", 'y');
|
||||
}
|
||||
|
||||
usleep($rand);
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
Nuh::$options['s'] = 0;
|
||||
|
||||
Nuh::$options['r'] = 0;
|
||||
|
||||
if (isset($data['events'])) {
|
||||
|
||||
foreach ($data['events'] as $event) {
|
||||
|
||||
Notice::note($event['season']['name'].' '.$day, 'bb');
|
||||
|
||||
$folder = app_path().self::$storage_path.$day.'/'.$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 = Nuh::$options['base_url']."api/v1/event/$event_id/statistics";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
Notice::note("Sleep $rand msec", 'y');
|
||||
}
|
||||
usleep($rand);
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder.'/statistics.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
|
||||
$event_id = $event['id'];
|
||||
|
||||
$url = Nuh::$options['base_url']."api/v1/event/$event_id/lineups";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
Notice::note("Sleep $rand msec", 'y');
|
||||
}
|
||||
usleep($rand);
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder.'/lineups.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
|
||||
$event_id = $event['id'];
|
||||
|
||||
$url = Nuh::$options['base_url']."api/v1/event/$event_id/odds/1/all";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
Notice::note("Sleep $rand msec", 'y');
|
||||
}
|
||||
usleep($rand);
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder.'/odds.json', json_encode($data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ ini_set('magic_quotes_runtime', false);
|
||||
|
||||
class Special
|
||||
{
|
||||
|
||||
public static $max_days = 30;
|
||||
|
||||
public static Carbon $days_back;
|
||||
|
||||
public static $storage_path = '/Console/Commands/Grapper/Sofascore/worldcup-teams/';
|
||||
@@ -21,7 +21,7 @@ class Special
|
||||
{
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
|
||||
$url = Nuh::$options['base_url'] . "/api/v1/world-cup/meet-the-team";
|
||||
$url = Nuh::$options['base_url'].'/api/v1/world-cup/meet-the-team';
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
@@ -38,7 +38,7 @@ class Special
|
||||
$teams[] = [
|
||||
'id' => $team['team']['id'],
|
||||
'slug' => $team['team']['slug'],
|
||||
'name' => $team['team']['name']
|
||||
'name' => $team['team']['name'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,9 @@ class Special
|
||||
|
||||
Nuh::$options['s'] = 0;
|
||||
|
||||
Nuh::$options['r'] = 0;
|
||||
Nuh::$options['r'] = 0;
|
||||
|
||||
$url = 'https://www.sofascore.com/api/v1/team/' . $team['id'] . '/events/last/0';
|
||||
$url = 'https://www.sofascore.com/api/v1/team/'.$team['id'].'/events/last/0';
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
@@ -66,7 +66,7 @@ class Special
|
||||
|
||||
$starttime = Carbon::createFromTimestamp($event['startTimestamp'])->format('Y-m-d');
|
||||
|
||||
$folder = app_path() . self::$storage_path . $starttime . '/' . $event['tournament']['slug'] . '/' . $event['slug'];
|
||||
$folder = app_path().self::$storage_path.$starttime.'/'.$event['tournament']['slug'].'/'.$event['slug'];
|
||||
|
||||
File::makeDirectory($folder, 0775, true, true);
|
||||
|
||||
@@ -74,13 +74,13 @@ class Special
|
||||
* EVENT event basic
|
||||
*********************************/
|
||||
|
||||
File::put($folder . '/event.json', json_encode($event));
|
||||
File::put($folder.'/event.json', json_encode($event));
|
||||
|
||||
/*********************************
|
||||
* EVENT statistics
|
||||
*********************************/
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/statistics";
|
||||
$url = Nuh::$options['base_url']."api/v1/event/$event_id/statistics";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
@@ -90,13 +90,13 @@ class Special
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder . '/statistics.json', json_encode($data));
|
||||
File::put($folder.'/statistics.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/lineups";
|
||||
$url = Nuh::$options['base_url']."api/v1/event/$event_id/lineups";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
@@ -106,14 +106,14 @@ class Special
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder . '/lineups.json', json_encode($data));
|
||||
File::put($folder.'/lineups.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
$event_id = $event['id'];
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/odds/1/all";
|
||||
$url = Nuh::$options['base_url']."api/v1/event/$event_id/odds/1/all";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
@@ -123,7 +123,7 @@ class Special
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
File::put($folder . '/odds.json', json_encode($data));
|
||||
File::put($folder.'/odds.json', json_encode($data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user