wip
This commit is contained in:
1 parent
5f4a788927
commit
f4f01a58fa
13 files changed
+239
-137
No files matched your search
@@ -16,10 +16,14 @@ ini_set('magic_quotes_runtime', false);
|
||||
|
||||
class Sofascore
|
||||
{
|
||||
public static string $storage;
|
||||
|
||||
public static function switch()
|
||||
{
|
||||
$function = Nuh::$options['fun'];
|
||||
|
||||
self::$storage = storage_path('sofascore_data');
|
||||
|
||||
switch ($function) {
|
||||
case 1:
|
||||
PlayerPerSeason::run();
|
||||
@@ -28,23 +32,23 @@ class Sofascore
|
||||
SettingsToLocal::run();
|
||||
break;
|
||||
case 3:
|
||||
CreateZip::run();
|
||||
break;
|
||||
case 4:
|
||||
SendMail::run();
|
||||
break;
|
||||
case 5:
|
||||
DaysTournament::run();
|
||||
break;
|
||||
case 6:
|
||||
Grapper::load();
|
||||
break;
|
||||
case 7:
|
||||
TaskConfig::start();
|
||||
break;
|
||||
case 8:
|
||||
case 4:
|
||||
DaysTournament::run();
|
||||
break;
|
||||
case 5:
|
||||
Grapper::load();
|
||||
break;
|
||||
case 6:
|
||||
TaskConfig::end();
|
||||
break;
|
||||
case 7:
|
||||
CreateZip::run();
|
||||
break;
|
||||
case 8:
|
||||
SendMail::run();
|
||||
break;
|
||||
|
||||
default:
|
||||
Notice::note('id not valid', 'br', 1);
|
||||
|
||||
@@ -14,7 +14,7 @@ class CreateZip
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
|
||||
$days = LoadDays::load();
|
||||
|
||||
|
||||
foreach ($days as $d) {
|
||||
|
||||
$day = $d['day'];
|
||||
@@ -23,7 +23,7 @@ class CreateZip
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
Notice::note(\count($days).' days as zip created', 'bb');
|
||||
Notice::note('zips created', 'bb');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class DaysTournament
|
||||
|
||||
if ($has) {
|
||||
if ($debug) {
|
||||
Notice::note("All tournament for $day have been allready grapped", 'r');
|
||||
Notice::note("All tournament for $day have been allready grapped", 'g');
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper;
|
||||
@@ -15,17 +16,15 @@ use Illuminate\Support\Facades\File;
|
||||
|
||||
class Grapper
|
||||
{
|
||||
|
||||
/**
|
||||
* last 3 days = task 1
|
||||
*
|
||||
* nuh --d --f 67 --fun=6 --task=1
|
||||
*/
|
||||
|
||||
public static function load()
|
||||
{
|
||||
/**
|
||||
* yesterday
|
||||
*
|
||||
* nuh --d --f 67 --fun=6 --task=1
|
||||
*
|
||||
* 1783710000
|
||||
* 10 July 2026 09:00:00 PM CEST
|
||||
*/
|
||||
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
|
||||
$force = Nuh::$options['f'] ?? 0;
|
||||
@@ -38,6 +37,15 @@ class Grapper
|
||||
|
||||
// dd($active_tournaments->toArray());
|
||||
|
||||
|
||||
/**
|
||||
* empty grapping folder
|
||||
* empty mailing text
|
||||
*/
|
||||
// File::cleanDirectory(Sofascore::$storage); dd('clead dir');
|
||||
|
||||
SofaScoreEventGrapped::query()->update(['in_current_grapper' => false]);
|
||||
|
||||
foreach ($active_tournaments as $tournament) {
|
||||
|
||||
if ($debug) {
|
||||
@@ -61,8 +69,6 @@ class Grapper
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
// dd($data);
|
||||
|
||||
Nuh::$options['s'] = 0;
|
||||
|
||||
Nuh::$options['r'] = 0;
|
||||
@@ -72,15 +78,25 @@ class Grapper
|
||||
foreach ($data['events'] as $event) {
|
||||
|
||||
$now = Carbon::now()->subHours(4);
|
||||
$starttime = Carbon::createFromTimestamp($event->startTimestamp);
|
||||
$starttime = Carbon::createFromTimestamp($event['startTimestamp']);
|
||||
|
||||
if ($now->greaterThan($starttime)) {
|
||||
|
||||
$event_grapped = SofaScoreEventGrapped::where('id', $event['id'])->first();
|
||||
$event_grapped['name'] = $event->homeTeam['name'] . ' vs ' . $event->awayTeam['name'];
|
||||
$event_grapped['url'] = $url;
|
||||
Sleeper::rand();
|
||||
|
||||
$folder = storage_path('sofascore_data') . $day . '/' . $event['tournament']['slug'] . '/' . $event['slug'];
|
||||
if ($debug) {
|
||||
Notice::note($day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'bg');
|
||||
}
|
||||
|
||||
$grapped = SofaScoreEventGrapped::firstOrNew(['id' => $event['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->in_current_grapper = true;
|
||||
|
||||
$folder = Sofascore::$storage . '/' . $day . '/' . $event['tournament']['slug'] . '/' . $event['slug'];
|
||||
|
||||
File::makeDirectory($folder, 0775, true, true);
|
||||
|
||||
@@ -96,77 +112,79 @@ class Grapper
|
||||
|
||||
$event_id = $event['id'];
|
||||
|
||||
if ($force || !$event_grapped['got_statistics'] && $event->hasEventPlayerStatistics) {
|
||||
// if (!$grapped['got_statistics'] && isset($event['hasEventPlayerStatistics']) && $event['hasEventPlayerStatistics'] == true) {
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/statistics";
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/statistics";
|
||||
|
||||
Sleeper::rand();
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/statistics.json', json_encode($data));
|
||||
File::put($folder . '/statistics.json', json_encode($data));
|
||||
|
||||
$event_grapped['got_statistics'] = 1;
|
||||
}
|
||||
$grapped->got_statistics = 1;
|
||||
// }
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
|
||||
if ($force || !$event_grapped['got_lineups']) {
|
||||
// if (!$grapped['got_lineups']) {
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/lineups";
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/lineups";
|
||||
|
||||
Sleeper::rand();
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/lineups.json', json_encode($data));
|
||||
File::put($folder . '/lineups.json', json_encode($data));
|
||||
|
||||
$event_grapped['got_lineups'] = 1;
|
||||
}
|
||||
$grapped->got_lineups = 1;
|
||||
// }
|
||||
|
||||
/*********************************
|
||||
* EVENT odds
|
||||
*********************************/
|
||||
|
||||
if ($force || !$event_grapped['got_odds']) {
|
||||
// if (!$grapped['got_odds']) {
|
||||
|
||||
$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";
|
||||
|
||||
Sleeper::rand();
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/odds.json', json_encode($data));
|
||||
File::put($folder . '/odds.json', json_encode($data));
|
||||
|
||||
$event_grapped['got_odds'] = 1;
|
||||
}
|
||||
$grapped->got_odds = 1;
|
||||
// }
|
||||
|
||||
/*********************************
|
||||
* EVENT incidents
|
||||
*********************************/
|
||||
|
||||
if ($force || !$event_grapped['got_incidents']) {
|
||||
// if (!$grapped['got_incidents']) {
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/incidents";
|
||||
$url = Nuh::$options['base_url'] . "api/v1/event/$event_id/incidents";
|
||||
|
||||
Sleeper::rand();
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/incidents.json', json_encode($data));
|
||||
File::put($folder . '/incidents.json', json_encode($data));
|
||||
|
||||
$event_grapped['got_incidents'] = 1;
|
||||
}
|
||||
$grapped->got_incidents = 1;
|
||||
// }
|
||||
|
||||
$grapped->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class Sleeper
|
||||
if ($langsam) {
|
||||
$sleep = rand(3000000, 6000000);
|
||||
} else {
|
||||
$sleep = rand(500000, 100000);
|
||||
$sleep = rand(100000, 150000);
|
||||
}
|
||||
usleep($sleep);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays;
|
||||
use App\Console\Commands\Nuh;
|
||||
use App\Mail\SofaScoreDataMail;
|
||||
use App\Models\SofaScoreEventGrapped;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
@@ -20,25 +23,20 @@ class SendMail
|
||||
|
||||
$day = $d['day'];
|
||||
|
||||
$zip_file = storage_path('sofascore_data') . '/' . $day . '.zip';
|
||||
$message = self::createMailText($day);
|
||||
|
||||
$zip_file = Sofascore::$storage . '/' . $day . '.zip';
|
||||
|
||||
if (File::exists($zip_file)) {
|
||||
|
||||
Mail::to('hermann.telser@gmail.com')
|
||||
->cc('ubaldo.perrucci@gmail.com')
|
||||
->send(
|
||||
new SofaScoreDataMail($day, $message, $zip_file)
|
||||
);
|
||||
if ($debug) {
|
||||
Notice::note('Mail send' . $day);
|
||||
}
|
||||
|
||||
|
||||
Mail::send([], [], function ($message) use ($day, $zip_file) {
|
||||
|
||||
$message->to('hermann.telser@gmail.com', 'sofa archive ' . $day)
|
||||
->cc('ubaldo.perrucci@gmail.com', 'sofa archive ' . $day)
|
||||
->subject("sofa archive $day")
|
||||
->attach($zip_file, [
|
||||
'mime' => 'application/x-zip-compressed',
|
||||
'as' => 'sofa archive ' . $day . '.zip',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +44,16 @@ class SendMail
|
||||
Notice::note('Mail send', 'g');
|
||||
}
|
||||
}
|
||||
|
||||
public static function createMailText(string $day)
|
||||
{
|
||||
$res = SofaScoreEventGrapped::where('day', $day)->get();
|
||||
$text = "## Mail Content $day
|
||||
";
|
||||
foreach ($res as $value) {
|
||||
$text .= "### $value->liga * $value->name * $value->starttime
|
||||
";
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user