wip del err
This commit is contained in:
1 parent
812736ca9a
commit
9bcd4432c6
1210 files changed
-220941
No files matched your search
@@ -1,163 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits\Sofascore;
|
||||
|
||||
use App\Models\SofaScoreDayTournament;
|
||||
use App\Models\SofaScoreEventGrapped;
|
||||
use App\Models\SofaScoreTaskDay;
|
||||
use App\Services\CloudflareSolverService;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
trait GrappingEvent
|
||||
{
|
||||
protected function get_event(string $day, array $tournament)
|
||||
{
|
||||
$res = SofaScoreDayTournament::whereDate('day', '=', $day)->where('tournament_id', $tournament['sofa_score_tournament_id'])->first();
|
||||
|
||||
if ($res) {
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note("$day - " . $tournament['tournament']['name'] . ' - ' . $tournament['sofa_score_tournament_id'], 'bb');
|
||||
}
|
||||
|
||||
$url = $this->base_url . 'api/v1/unique-tournament/' . $tournament['sofa_score_tournament_id'] . "/scheduled-events/$day";
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note($url, 'p');
|
||||
}
|
||||
|
||||
$this->sleep(1);
|
||||
|
||||
$cloudflareService = new CloudflareSolverService;
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
if (isset($data['events'])) {
|
||||
|
||||
foreach ($data['events'] as $event) {
|
||||
|
||||
if (! $this->restart && SofaScoreEventGrapped::where('grapper_id', $this->task_id)->where('id', (int) $event['id'])->exists()) {
|
||||
if ($this->debug) {
|
||||
Notice::note('DB - Allready grapped at ' . $day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'b');
|
||||
}
|
||||
} else {
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note("$day - " . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'g');
|
||||
}
|
||||
|
||||
$folder = strtolower("$this->data_dir/$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 = $this->base_url . "api/v1/event/$event_id/statistics";
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$this->sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put("$folder/statistics.json", json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
|
||||
$url = $this->base_url . "api/v1/event/$event_id/lineups";
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$this->sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put("$folder/lineups.json", json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT odds
|
||||
*********************************/
|
||||
|
||||
$url = $this->base_url . "api/v1/event/$event_id/odds/1/all";
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$this->sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put("$folder/odds.json", json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT incidents
|
||||
*********************************/
|
||||
|
||||
$url = $this->base_url . "api/v1/event/$event_id/incidents";
|
||||
|
||||
if ($this->debug) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$this->sleep();
|
||||
|
||||
$data = $cloudflareService->getJsonFromUrl($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put("$folder/incidents.json", json_encode($data));
|
||||
|
||||
$starttime = Carbon::createFromTimestamp($event['startTimestamp']);
|
||||
|
||||
SofaScoreEventGrapped::updateOrCreate([
|
||||
'id' => (int) $event['id'],
|
||||
], [
|
||||
'grapper_id' => $this->task_id,
|
||||
'day' => $day,
|
||||
'liga' => $event['tournament']['name'],
|
||||
'name' => $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'],
|
||||
'url' => $url,
|
||||
'starttime' => $starttime->toDateTimeString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($this->debug) {
|
||||
Notice::note($day . ' - ' . $tournament['tournament']['name'] . " no events", 'y');
|
||||
}
|
||||
}
|
||||
|
||||
SofaScoreTaskDay::updateOrCreate([
|
||||
'grapper_id' => (int) $this->task_id,
|
||||
'day' => $day,
|
||||
], [
|
||||
'done' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user