wip
This commit is contained in:
1 parent
d50df325ef
commit
267b5b9583
8 files changed
+237
-193
No files matched your search
@@ -46,9 +46,10 @@ class Grap extends Command
|
||||
$txt .= '--F force DayTournament links' . PHP_EOL;
|
||||
$txt .= '--c clear grap dir' . PHP_EOL;
|
||||
$txt .= '--m mail only' . PHP_EOL;
|
||||
$txt .= '--g grap & excel only' . PHP_EOL;
|
||||
$txt .= '--R read file' . PHP_EOL;
|
||||
$txt .= '--S save to file' . PHP_EOL;
|
||||
$txt .= '--C clear folder' . PHP_EOL;
|
||||
$txt .= '--G grap' . PHP_EOL;
|
||||
$txt .= '--E make excel' . PHP_EOL;
|
||||
$txt .= '--M mail' . PHP_EOL;
|
||||
$txt .= '--folder' . PHP_EOL;
|
||||
$txt .= '-----------------------------------------------------------' . PHP_EOL;
|
||||
$txt .= 'FUNCTION' . PHP_EOL;
|
||||
@@ -69,18 +70,20 @@ class Grap extends Command
|
||||
|
||||
case 1:
|
||||
// DAILY
|
||||
SetStorage::set(1);
|
||||
|
||||
RemoveDir::remove();
|
||||
|
||||
// with --m just resend mail
|
||||
if (! self::$options['m']) {
|
||||
if (self::$options['C']) {
|
||||
Grapper::load(1);
|
||||
}
|
||||
|
||||
if (self::$options['G']) {
|
||||
Grapper::load(1);
|
||||
}
|
||||
|
||||
if (self::$options['E']) {
|
||||
MakeExcel::create();
|
||||
}
|
||||
|
||||
// with --g just grap & excel
|
||||
if (! self::$options['g']) {
|
||||
if (self::$options['M']) {
|
||||
SendMail::run(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ use App\Models\SofaScoreTaskTournament;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Grapper
|
||||
{
|
||||
@@ -44,16 +43,11 @@ class Grapper
|
||||
|
||||
default:
|
||||
$active_tournaments = SofaScoreTaskTournament::with('tournament')->where('sofa_score_task_id', $task_id)->where('disabled', false)->get();
|
||||
// $active_tournaments = SofaScoreTaskTournament::with('tournament')->where('sofa_score_tournament_id', 247)->where('sofa_score_task_id', $task_id)->where('disabled', false)->get();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* daily restart always
|
||||
*/
|
||||
if (\in_array($task_id, [1, 2])) {
|
||||
SofaScoreEventGrapped::where('grapper_id', $task_id)->delete();
|
||||
}
|
||||
/**
|
||||
* Restart
|
||||
*/
|
||||
@@ -77,22 +71,33 @@ class Grapper
|
||||
|
||||
DaysTournament::get($day);
|
||||
|
||||
dd($active_tournaments);
|
||||
|
||||
foreach ($active_tournaments as $tournament) {
|
||||
|
||||
$res = SofaScoreDayTournament::whereDate('day', '=', $day)->where('tournament_id', $tournament->sofa_score_tournament_id)->first();
|
||||
|
||||
if ($res) {
|
||||
|
||||
// if ($debug) {
|
||||
// Notice::note($day, 'g');
|
||||
// }
|
||||
if ($debug) {
|
||||
Notice::note($tournament->sofa_score_tournament_id, 'bb');
|
||||
}
|
||||
|
||||
if (! $force)
|
||||
Sleeper::rand(1);
|
||||
else
|
||||
Sleeper::rand();
|
||||
|
||||
if ($debug) {
|
||||
Notice::note($day, 'br');
|
||||
}
|
||||
|
||||
$url = Grap::$options['base_url'] . "api/v1/unique-tournament/$tournament->sofa_score_tournament_id/scheduled-events/$day";
|
||||
|
||||
Sleeper::rand(1);
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
Notice::note($data, 'bb');
|
||||
|
||||
|
||||
if (isset($data['events'])) {
|
||||
|
||||
if ($debug) {
|
||||
@@ -102,11 +107,8 @@ class Grapper
|
||||
foreach ($data['events'] as $event) {
|
||||
|
||||
Grap::$useragent = rand(1, 6);
|
||||
if (Storage::directoryExists(Grap::$storage . '/' . $day)) {
|
||||
if ($debug) {
|
||||
Notice::note('FOLDER - Allready grapped at ' . $day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'g');
|
||||
}
|
||||
} else if (! $force && SofaScoreEventGrapped::where('id', (int) $event['id'])->exists()) {
|
||||
|
||||
if (! $force && SofaScoreEventGrapped::where('grapper_id', $task_id)->where('id', (int) $event['id'])->exists()) {
|
||||
if ($debug) {
|
||||
Notice::note('DB - Allready grapped at ' . $day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'g');
|
||||
}
|
||||
@@ -118,105 +120,103 @@ class Grapper
|
||||
|
||||
$starttime = Carbon::createFromTimestamp($event['startTimestamp']);
|
||||
|
||||
if ($now->greaterThan($starttime) && $starttime->isSameDay($carbon_day)) {
|
||||
// dd($starttime);
|
||||
|
||||
// if ($now->greaterThan($starttime) && $starttime->isSameDay($carbon_day)) {
|
||||
|
||||
if (! $force)
|
||||
Sleeper::rand(1);
|
||||
|
||||
if ($debug) {
|
||||
Notice::note($day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'bg');
|
||||
}
|
||||
|
||||
$grapped = SofaScoreEventGrapped::firstOrNew(['id' => $event['id']]);
|
||||
$grapped->grapper_id = $task_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();
|
||||
|
||||
$folder = strtolower(Grap::$storage . '/' . $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 = Grap::$options['base_url'] . "api/v1/event/$event_id/statistics";
|
||||
|
||||
else
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/statistics.json', json_encode($data));
|
||||
|
||||
$grapped->got_statistics = 1;
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
|
||||
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/lineups";
|
||||
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/lineups.json', json_encode($data));
|
||||
|
||||
$grapped->got_lineups = 1;
|
||||
|
||||
/*********************************
|
||||
* EVENT odds
|
||||
*********************************/
|
||||
|
||||
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/odds/1/all";
|
||||
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/odds.json', json_encode($data));
|
||||
|
||||
$grapped->got_odds = 1;
|
||||
|
||||
/*********************************
|
||||
* EVENT incidents
|
||||
*********************************/
|
||||
|
||||
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/incidents";
|
||||
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/incidents.json', json_encode($data));
|
||||
|
||||
$grapped->got_incidents = 1;
|
||||
|
||||
$grapped->save();
|
||||
if ($debug) {
|
||||
Notice::note($day . ' - ' . $event['homeTeam']['name'] . ' vs ' . $event['awayTeam']['name'], 'bg');
|
||||
}
|
||||
|
||||
$folder = strtolower(Grap::$storage . '/' . $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 = Grap::$options['base_url'] . "api/v1/event/$event_id/statistics";
|
||||
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/statistics.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT lineups
|
||||
*********************************/
|
||||
|
||||
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/lineups";
|
||||
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/lineups.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT odds
|
||||
*********************************/
|
||||
|
||||
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/odds/1/all";
|
||||
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/odds.json', json_encode($data));
|
||||
|
||||
/*********************************
|
||||
* EVENT incidents
|
||||
*********************************/
|
||||
|
||||
$url = Grap::$options['base_url'] . "api/v1/event/$event_id/incidents";
|
||||
|
||||
Sleeper::rand();
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
$data['id'] = $event_id;
|
||||
|
||||
File::put($folder . '/incidents.json', json_encode($data));
|
||||
|
||||
$grapped = SofaScoreEventGrapped::firstOrNew(['id' => $event['id']]);
|
||||
$grapped->grapper_id = $task_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->save();
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SofaScoreTaskDay::updateOrCreate([
|
||||
'grapper_id' => (int) $task_id,
|
||||
'day' => $day,
|
||||
@@ -227,8 +227,13 @@ class Grapper
|
||||
$count++;
|
||||
|
||||
if ($debug) {
|
||||
Notice::note("$count days done", 'p');
|
||||
Notice::note("$count days done, sleep 10-20 sec", 'p');
|
||||
}
|
||||
|
||||
if (! $force)
|
||||
Sleeper::rand(2);
|
||||
else
|
||||
Sleeper::rand();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Console\Commands\Grapper\Sofascore;
|
||||
|
||||
use App\Console\Commands\Grap;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\CurlLivescore;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\CurlSofa;
|
||||
use App\Utilities\Notice;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
@@ -19,17 +20,21 @@ class GrapperTest
|
||||
|
||||
$testfile = 'livescore.txt';
|
||||
|
||||
$path = __DIR__.self::$testfiles.$testfile;
|
||||
$path = __DIR__ . self::$testfiles . $testfile;
|
||||
|
||||
Notice::note('Grapper testing '.$testfile, 'b');
|
||||
Notice::note('Grapper testing ' . $testfile, 'b');
|
||||
|
||||
$url = 'https://www.livescore.in/horse-racing/canada/woodbine-2020/';
|
||||
// $url = 'https://www.livescore.in/horse-racing/canada/woodbine-2020/';
|
||||
$url = 'https://www.sofascore.com/api/v1/event/16298660/statistics';
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
Notice::note($data, '', 1);
|
||||
|
||||
if ($read) {
|
||||
Notice::note('data read localy', 'p');
|
||||
|
||||
$data = file_get_contents($path);
|
||||
|
||||
} else {
|
||||
$data = CurlLivescore::load($url);
|
||||
}
|
||||
@@ -58,7 +63,7 @@ class GrapperTest
|
||||
$teams = $xpath->query("//div[contains(@class, 'event__participant')]");
|
||||
|
||||
foreach ($teams as $team) {
|
||||
echo trim($team->nodeValue).PHP_EOL;
|
||||
echo trim($team->nodeValue) . PHP_EOL;
|
||||
}
|
||||
|
||||
Notice::note($data, 'p', 1);
|
||||
|
||||
@@ -15,7 +15,13 @@ class CurlSofa
|
||||
if ($debug) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
// $useragents = [];
|
||||
// $useragents[1] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36";
|
||||
// $useragents[2] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36";
|
||||
// $useragents[3] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15";
|
||||
// $useragents[4] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0";
|
||||
// $useragents[5] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0";
|
||||
// $useragents[6] = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36";
|
||||
$useragents = [];
|
||||
$useragents[1] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15';
|
||||
$useragents[2] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15';
|
||||
@@ -24,13 +30,31 @@ class CurlSofa
|
||||
$useragents[5] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0';
|
||||
$useragents[6] = 'Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36';
|
||||
|
||||
// GET /api/v1/config/default-unique-tournaments/AT/football HTTP/2
|
||||
// Host: www.sofascore.com
|
||||
// User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:139.0) Gecko/20100101 Firefox/139.0
|
||||
// Accept: */*
|
||||
// Accept-Language: de,en-US;q=0.7,en;q=0.3
|
||||
// Accept-Encoding: gzip, deflate, br, zstd
|
||||
// Referer: https://www.sofascore.com/
|
||||
// X-Requested-With: 629800
|
||||
// DNT: 1
|
||||
// Sec-GPC: 1
|
||||
// Connection: keep-alive
|
||||
// Sec-Fetch-Dest: empty
|
||||
// Sec-Fetch-Mode: cors
|
||||
// Sec-Fetch-Site: same-origin
|
||||
// Priority: u=4
|
||||
// Pragma: no-cache
|
||||
// Cache-Control: no-cache
|
||||
// TE: trailers
|
||||
$headers = [
|
||||
'User-Agent: ' . $useragents[Grap::$useragent],
|
||||
'Accept: */*',
|
||||
'Accept-Language: de,en-US;q=0.7,en;q=0.3',
|
||||
'Accept-Encoding: gzip, deflate, br, zstd',
|
||||
'Referer: https://www.sofascore.com/',
|
||||
'X-Requested-With: 5c6b10',
|
||||
'X-Requested-With: 629800',
|
||||
'DNT: 1',
|
||||
'Sec-GPC: 1',
|
||||
'Connection: keep-alive',
|
||||
@@ -48,11 +72,10 @@ class CurlSofa
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// This line magically handles all decompression out-of-the-box:
|
||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||
$data = curl_exec($ch);
|
||||
|
||||
$data = gzdecode($data);
|
||||
|
||||
$data = json_decode($data, true);
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -46,8 +46,8 @@ class LoadDays
|
||||
|
||||
default:
|
||||
$from = ValidateDate::get($task->day_from);
|
||||
$to = ValidateDate::get($task->day_to);
|
||||
$from = Carbon::createFromDate($from);
|
||||
$to = ValidateDate::get($task->day_to);
|
||||
$to = Carbon::createFromDate($to);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user