wip
This commit is contained in:
1 parent
28ed78c864
commit
59f2eeec11
8 files changed
+342
-132
No files matched your search
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Actions\PlayerPerSeason;
|
||||
use App\Console\Commands\Grapper\Sofascore\Grapper;
|
||||
use App\Console\Commands\Grapper\Sofascore\GrapperTest;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\SetStorage;
|
||||
use App\Console\Commands\Grapper\Sofascore\MakeExcel;
|
||||
use App\Console\Commands\Grapper\Sofascore\Rose;
|
||||
@@ -16,14 +17,18 @@ use Illuminate\Console\Command;
|
||||
class Grap extends Command
|
||||
{
|
||||
public static $options = [];
|
||||
|
||||
public static string $storage;
|
||||
|
||||
public static string $zipfile;
|
||||
|
||||
public static string $folder;
|
||||
|
||||
public static string $excel;
|
||||
|
||||
public static string $useragent = '4';
|
||||
|
||||
protected $signature = 'grp {id=0} {day=0} {--folder=} {--d} {--r} {--f}';
|
||||
protected $signature = 'grp {id=0} {day=0} {--folder=} {--d} {--r} {--f} {--R} {--S}';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
@@ -33,25 +38,28 @@ class Grap extends Command
|
||||
self::$options['base_url'] = 'https://www.sofascore.com/';
|
||||
|
||||
if (! self::$options['id']) {
|
||||
$txt = 'PARAMETERS' . PHP_EOL;
|
||||
$txt .= '--d debug' . PHP_EOL;
|
||||
$txt .= '--r restart range' . PHP_EOL;
|
||||
$txt .= '--f force' . PHP_EOL;
|
||||
$txt .= '--folder' . PHP_EOL;
|
||||
$txt .= '-----------------------------------------------------------' . PHP_EOL;
|
||||
$txt .= 'FUNCTION' . PHP_EOL;
|
||||
$txt .= ' 1 grapper DAILY & subDays ( default 3)' . PHP_EOL;
|
||||
$txt .= ' 2 grapper DATE' . PHP_EOL;
|
||||
$txt .= ' 3 grapper RANGE' . PHP_EOL;
|
||||
$txt .= ' 4 grapper ROSE' . PHP_EOL;
|
||||
$txt .= ' 5 import to excel from folder' . PHP_EOL;
|
||||
$txt .= ' 6 playeer/season' . PHP_EOL;
|
||||
$txt .= ' 7 settings to local' . PHP_EOL;
|
||||
$txt .= ' 11 move SQL' . PHP_EOL;
|
||||
$txt = 'PARAMETERS'.PHP_EOL;
|
||||
$txt .= '--d debug'.PHP_EOL;
|
||||
$txt .= '--r restart range'.PHP_EOL;
|
||||
$txt .= '--f force'.PHP_EOL;
|
||||
$txt .= '--R read file'.PHP_EOL;
|
||||
$txt .= '--S save to file'.PHP_EOL;
|
||||
$txt .= '--folder'.PHP_EOL;
|
||||
$txt .= '-----------------------------------------------------------'.PHP_EOL;
|
||||
$txt .= 'FUNCTION'.PHP_EOL;
|
||||
$txt .= ' 1 grapper DAILY & subDays ( default 3)'.PHP_EOL;
|
||||
$txt .= ' 2 grapper DATE'.PHP_EOL;
|
||||
$txt .= ' 3 grapper RANGE'.PHP_EOL;
|
||||
$txt .= ' 4 grapper ROSE'.PHP_EOL;
|
||||
$txt .= ' 5 import to excel from folder'.PHP_EOL;
|
||||
$txt .= ' 6 playeer/season'.PHP_EOL;
|
||||
$txt .= ' 7 settings to local'.PHP_EOL;
|
||||
$txt .= ' 11 move SQL'.PHP_EOL;
|
||||
$txt .= ' 12 testing url for grapping'.PHP_EOL;
|
||||
Notice::note($txt, 'b', 1);
|
||||
}
|
||||
|
||||
Notice::note('Task Id ' . self::$options['id'], 'gb');
|
||||
Notice::note('Task Id '.self::$options['id'], 'gb');
|
||||
|
||||
switch (self::$options['id']) {
|
||||
|
||||
@@ -111,6 +119,10 @@ class Grap extends Command
|
||||
SqlMover::run();
|
||||
break;
|
||||
|
||||
case '12':
|
||||
GrapperTest::load();
|
||||
break;
|
||||
|
||||
default:
|
||||
Notice::note('function not implemented yet', 'br', 1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore;
|
||||
|
||||
use App\Console\Commands\Grap;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\CurlLivescore;
|
||||
use App\Utilities\Notice;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
|
||||
class GrapperTest
|
||||
{
|
||||
public static $testfiles = '/Testfiles/';
|
||||
|
||||
public static function load()
|
||||
{
|
||||
$read = Grap::$options['R'] ?? 0;
|
||||
$save = Grap::$options['S'] ?? 0;
|
||||
|
||||
$testfile = 'livescore.txt';
|
||||
|
||||
$path = __DIR__.self::$testfiles.$testfile;
|
||||
|
||||
Notice::note('Grapper testing '.$testfile, 'b');
|
||||
|
||||
$url = 'https://www.livescore.in/horse-racing/canada/woodbine-2020/';
|
||||
|
||||
if ($read) {
|
||||
Notice::note('data read localy', 'p');
|
||||
|
||||
$data = file_get_contents($path);
|
||||
|
||||
} else {
|
||||
$data = CurlLivescore::load($url);
|
||||
}
|
||||
|
||||
if ($save) {
|
||||
|
||||
file_put_contents($path, $data);
|
||||
|
||||
Notice::note('file saved localy', 'g');
|
||||
}
|
||||
|
||||
$dom = new DOMDocument;
|
||||
|
||||
// Prevent warnings caused by HTML5 tags that native DOMDocument doesn't fully understand
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
// Use mb_convert_encoding to ensure DOMDocument treats the input as UTF-8
|
||||
$dom->loadHTML(mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8'));
|
||||
libxml_clear_errors();
|
||||
|
||||
// 3. Use XPath to query specific HTML elements
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
// Example: Target match rows or team names (Update classes based on actual DOM structure)
|
||||
// Modern livescore sites often use classes like '.event__match' or '.event__participant'
|
||||
$teams = $xpath->query("//div[contains(@class, 'event__participant')]");
|
||||
|
||||
foreach ($teams as $team) {
|
||||
echo trim($team->nodeValue).PHP_EOL;
|
||||
}
|
||||
|
||||
Notice::note($data, 'p', 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore\Helper;
|
||||
|
||||
use App\Console\Commands\Grap;
|
||||
use App\Utilities\Notice;
|
||||
|
||||
// use ForceUTF8\Encoding;
|
||||
|
||||
class CurlLivescore
|
||||
{
|
||||
public static function load(string $url)
|
||||
{
|
||||
$debug = Grap::$options['d'] ?? 0;
|
||||
|
||||
if ($debug) {
|
||||
Notice::note($url, 'b');
|
||||
}
|
||||
|
||||
$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';
|
||||
$useragents[3] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
|
||||
$useragents[4] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15';
|
||||
$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';
|
||||
|
||||
$headers = [
|
||||
'GET /horse-racing/canada/woodbine-2020/ HTTP/1.1',
|
||||
'Host: www.livescore.in',
|
||||
'User-Agent: '.$useragents[Grap::$useragent],
|
||||
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
'Accept-Language: de,en-US;q=0.9,en;q=0.8',
|
||||
'Accept-Encoding: gzip, deflate, br, zstd',
|
||||
'Referer: https://www.livescore.in/horse-racing/canada/woodbine/archive/',
|
||||
'Upgrade-Insecure-Requests: 1',
|
||||
'Sec-Fetch-Dest: document',
|
||||
'Sec-Fetch-Mode: navigate',
|
||||
'Sec-Fetch-Site: same-origin',
|
||||
'Sec-Fetch-User: ?1',
|
||||
'Connection: keep-alive',
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||
|
||||
$data = curl_exec($ch);
|
||||
|
||||
// $data = Encoding::toUTF8($data);
|
||||
|
||||
// $data = gzdecode($data);
|
||||
|
||||
// $data = json_decode($data, true);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Whitespace-only changes.
@@ -15,6 +15,7 @@ use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Slider;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
@@ -23,7 +24,6 @@ use Filament\Schemas\Components\Utilities\Set;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\RawJs;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class Statistic extends BaseDashboard
|
||||
@@ -57,6 +57,25 @@ class Statistic extends BaseDashboard
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
// ToggleButtons::make('status')
|
||||
// ->columnSpanFull()
|
||||
// ->hiddenLabel()
|
||||
// ->inline()
|
||||
// ->default(1)
|
||||
// ->options([
|
||||
// '1' => 'Soccer',
|
||||
// '3' => 'Basketball',
|
||||
// '2' => 'Ice Hockey',
|
||||
// '5' => 'Tennis',
|
||||
// '27' => 'Horse Racing',
|
||||
// ])
|
||||
// ->icons([
|
||||
// '1' => 'icon-soccerball',
|
||||
// '3' => 'icon-basketball',
|
||||
// '2' => 'icon-icehockey',
|
||||
// '5' => 'icon-tennisball',
|
||||
// '27' => 'icon-horseracing',
|
||||
// ]),
|
||||
Grid::make([
|
||||
'default' => 1,
|
||||
'sm' => 3,
|
||||
@@ -67,10 +86,10 @@ class Statistic extends BaseDashboard
|
||||
Select::make('league_id')
|
||||
->live()
|
||||
->searchable()
|
||||
->prefixIconColor(fn(Get $get): string => $get('league_id') ? 'success' : 'danger')
|
||||
->prefixIconColor(fn (Get $get): string => $get('league_id') ? 'success' : 'danger')
|
||||
->prefixIcon('phosphor-trophy-fill')
|
||||
->hiddenLabel()
|
||||
->options(fn() => LoadStatisticFixturesLeaguesOptions::load(1))
|
||||
->options(fn () => LoadStatisticFixturesLeaguesOptions::load(1))
|
||||
->placeholder('League')
|
||||
->afterStateUpdated(function (callable $set, $state) {
|
||||
$set('match_id', null);
|
||||
@@ -81,7 +100,7 @@ class Statistic extends BaseDashboard
|
||||
Select::make('match_id')
|
||||
->live()
|
||||
->hiddenLabel()
|
||||
->prefixIconColor(fn(Get $get): string => $get('match_id') ? 'success' : 'danger')
|
||||
->prefixIconColor(fn (Get $get): string => $get('match_id') ? 'success' : 'danger')
|
||||
->prefixIcon('phosphor-calendar-check-fill')
|
||||
->options(function (Get $get) {
|
||||
return LoadStatisticFixturesMatchOptions::load($get('league_id'));
|
||||
@@ -105,12 +124,11 @@ class Statistic extends BaseDashboard
|
||||
}
|
||||
})
|
||||
->prefixIcon('phosphor-users-three-fill')
|
||||
->hidden(fn(Get $get) => $get('similar_past_matches') != 'none')
|
||||
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
|
||||
->options(function (Get $get) {
|
||||
if ($get('match_id')) {
|
||||
$res = StatisticFixtures::where('id', $get('match_id'))->first();
|
||||
|
||||
|
||||
$arr = [];
|
||||
if ($res) {
|
||||
$arr[$res->home_id] = SofaScoreRosa::query()->where('ss_team_id', $res->home_id)->value('ss_team_name');
|
||||
@@ -134,9 +152,9 @@ class Statistic extends BaseDashboard
|
||||
Action::make('iconInfo')
|
||||
->color('success')
|
||||
->icon('phosphor-question-fill')
|
||||
->tooltip(fn() => 'Team Position')
|
||||
->tooltip(fn () => 'Team Position')
|
||||
)
|
||||
->hidden(fn(Get $get) => $get('similar_past_matches') != 'none')
|
||||
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
|
||||
->default('all')
|
||||
->selectablePlaceholder(false)
|
||||
->options([
|
||||
@@ -189,13 +207,13 @@ class Statistic extends BaseDashboard
|
||||
->hiddenLabel()
|
||||
->prefix('SPM')
|
||||
->placeholder('Similar Past Matches')
|
||||
->suffix(fn(Get $get): string|HtmlString => $get('similar_past_matches') != 'none' ? new HtmlString('<div class="text-center w-24 font-bold rounded p-1 bg-blue-600 dark:bg-blue-700 text-white dark:text-gray-300">± ' . $get('accuracy') . '</div>') : '')
|
||||
->suffix(fn (Get $get): string|HtmlString => $get('similar_past_matches') != 'none' ? new HtmlString('<div class="text-center w-24 font-bold rounded p-1 bg-blue-600 dark:bg-blue-700 text-white dark:text-gray-300">± '.$get('accuracy').'</div>') : '')
|
||||
->prefixAction(
|
||||
Action::make('iconInfo')
|
||||
->icon('phosphor-question-fill')
|
||||
// ->color(fn(Get $get): string => $get('similar_past_matches') != 'none' ? 'success' : 'primary')
|
||||
->color('success')
|
||||
->tooltip(fn() => $this->tooltip_similar_past_matches())
|
||||
->tooltip(fn () => $this->tooltip_similar_past_matches())
|
||||
)
|
||||
->default('none')
|
||||
->selectablePlaceholder(false)
|
||||
@@ -212,7 +230,7 @@ class Statistic extends BaseDashboard
|
||||
Slider::make('accuracy')
|
||||
->live()
|
||||
->hiddenLabel()
|
||||
->hidden(fn(Get $get) => $get('similar_past_matches') == 'none')
|
||||
->hidden(fn (Get $get) => $get('similar_past_matches') == 'none')
|
||||
->fillTrack()
|
||||
->minValue(0)
|
||||
->maxValue(0.25)
|
||||
@@ -228,17 +246,17 @@ class Statistic extends BaseDashboard
|
||||
->hiddenLabel()
|
||||
->allowHtml()
|
||||
->placeholder('Player')
|
||||
->hidden(fn(Get $get) => $get('similar_past_matches') != 'none')
|
||||
->prefixIconColor(fn(Get $get): string => $get('similar_past_matches') == 'none' ? 'success' : '')
|
||||
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
|
||||
->prefixIconColor(fn (Get $get): string => $get('similar_past_matches') == 'none' ? 'success' : '')
|
||||
->prefixIcon('icon-player')
|
||||
->preload()
|
||||
->searchable()
|
||||
->extraAttributes(fn() => ['id' => 'player_selector'])
|
||||
->extraAttributes(fn () => ['id' => 'player_selector'])
|
||||
->suffixAction(
|
||||
Action::make('iconInfo')
|
||||
->icon('phosphor-question-fill')
|
||||
->color('success')
|
||||
->tooltip(fn() => $this->tooltip_player_info())
|
||||
->tooltip(fn () => $this->tooltip_player_info())
|
||||
)
|
||||
->options(function (Get $get) {
|
||||
return LoadPlayer::load($get);
|
||||
@@ -249,7 +267,7 @@ class Statistic extends BaseDashboard
|
||||
->placeholder('Time on field')
|
||||
->prefixIcon('phosphor-watch-fill')
|
||||
->default('all')
|
||||
->hidden(fn(Get $get) => ! $get('ss_player_id'))
|
||||
->hidden(fn (Get $get) => ! $get('ss_player_id'))
|
||||
->prefixIconColor('success')
|
||||
->selectablePlaceholder(false)
|
||||
->options([
|
||||
@@ -289,7 +307,7 @@ class Statistic extends BaseDashboard
|
||||
->placeholder('All Seasons')
|
||||
->prefixIconColor('success')
|
||||
// ->prefixIconColor(fn(Get $get): string => $get('season') ? 'success' : 'primary')
|
||||
->hidden(fn(Get $get) => $get('season_or_date') == 'date')
|
||||
->hidden(fn (Get $get) => $get('season_or_date') == 'date')
|
||||
->prefixIcon('phosphor-calendar-star-fill')
|
||||
->preload()
|
||||
->options(function (Get $get) {
|
||||
@@ -298,30 +316,30 @@ class Statistic extends BaseDashboard
|
||||
DatePicker::make('start_date')
|
||||
->live()
|
||||
->hiddenLabel()
|
||||
->hidden(fn(Get $get) => $get('season_or_date') == 'season')
|
||||
->hidden(fn (Get $get) => $get('season_or_date') == 'season')
|
||||
->native(false)
|
||||
->prefixIconColor(fn(Get $get): string => $get('start_date') ? 'success' : 'primary')
|
||||
->prefixIconColor(fn (Get $get): string => $get('start_date') ? 'success' : 'primary')
|
||||
->prefixIcon('phosphor-calendar-fill')
|
||||
->prefix('Start')
|
||||
->suffixAction(
|
||||
Action::make('clear_start')
|
||||
->icon('phosphor-x')
|
||||
->color('gray')
|
||||
->action(fn(Set $set) => $set('start_date', null))
|
||||
->action(fn (Set $set) => $set('start_date', null))
|
||||
),
|
||||
DatePicker::make('end_date')
|
||||
->live()
|
||||
->hiddenLabel()
|
||||
->hidden(fn(Get $get) => $get('season_or_date') == 'season')
|
||||
->hidden(fn (Get $get) => $get('season_or_date') == 'season')
|
||||
->native(false)
|
||||
->prefixIconColor(fn(Get $get): string => $get('end_date') ? 'success' : 'primary')
|
||||
->prefixIconColor(fn (Get $get): string => $get('end_date') ? 'success' : 'primary')
|
||||
->prefixIcon('phosphor-calendar-fill')
|
||||
->prefix('End')
|
||||
->suffixAction(
|
||||
Action::make('clear_end')
|
||||
->icon('phosphor-x')
|
||||
->color('gray')
|
||||
->action(fn(Set $set) => $set('end_date', null))
|
||||
->action(fn (Set $set) => $set('end_date', null))
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user