wip
This commit is contained in:
1 parent
23a367c493
commit
fb31825b22
7 files changed
+269
-52
No files matched your search
@@ -3,9 +3,10 @@
|
||||
namespace App\Console\Commands\Grapper\Sofascore;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore\Specials\CreateZip;
|
||||
use App\Console\Commands\Grapper\Sofascore\Specials\LeaguesToLocal;
|
||||
use App\Console\Commands\Grapper\Sofascore\Specials\DaysTournament;
|
||||
use App\Console\Commands\Grapper\Sofascore\Specials\PlayerPerSeason;
|
||||
use App\Console\Commands\Grapper\Sofascore\Specials\SendMail;
|
||||
use App\Console\Commands\Grapper\Sofascore\Specials\SettingsToLocal;
|
||||
use App\Console\Commands\Nuh;
|
||||
use App\Utilities\Notice;
|
||||
|
||||
@@ -39,7 +40,7 @@ class Special
|
||||
if($debug){
|
||||
Notice::note('copy active tournament to local', 'y');
|
||||
}
|
||||
LeaguesToLocal::run();
|
||||
SettingsToLocal::run();
|
||||
break;
|
||||
case 3:
|
||||
if($debug){
|
||||
@@ -53,6 +54,13 @@ class Special
|
||||
}
|
||||
SendMail::run();
|
||||
break;
|
||||
case 5:
|
||||
if($debug){
|
||||
Notice::note('grap tornamenst available for given day', 'y');
|
||||
}
|
||||
DaysTournament::run();
|
||||
break;
|
||||
|
||||
default:
|
||||
Notice::note('run special "prc" id missing', 'br', 1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore\Specials;
|
||||
|
||||
use App\Console\Commands\Grapper\Sofascore\CurlSofa;
|
||||
use App\Console\Commands\Grapper\Sofascore\Tools\LoadDays;
|
||||
use App\Console\Commands\Nuh;
|
||||
use App\Models\SofaScoreCategorie;
|
||||
use App\Models\SofaScoreDayTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Utilities\Notice;
|
||||
|
||||
class DaysTournament
|
||||
{
|
||||
public static function run()
|
||||
{
|
||||
$days = LoadDays::load();
|
||||
|
||||
dd($days);
|
||||
|
||||
foreach ($days as $day) {
|
||||
|
||||
$page = 1;
|
||||
|
||||
while ($page) {
|
||||
|
||||
$url = Nuh::$options['base_url'] . "api/v1/sport/$sport->ss_slug/scheduled-tournaments/$day/page/$page";
|
||||
|
||||
$rand = rand(500000, 1000000);
|
||||
if ($debug) {
|
||||
Notice::note("Sleep $rand msec", 'y');
|
||||
}
|
||||
usleep($rand);
|
||||
|
||||
$data = CurlSofa::load($url);
|
||||
|
||||
if ($data['hasNextPage']) {
|
||||
$page++;
|
||||
} else {
|
||||
$page = false;
|
||||
}
|
||||
|
||||
// $page = false;
|
||||
|
||||
foreach ($data['scheduled'] as $row) {
|
||||
|
||||
if (isset($row['tournament']['uniqueTournament'])) {
|
||||
$tournament = $row['tournament']['uniqueTournament'];
|
||||
} else {
|
||||
$tournament = $row['tournament'];
|
||||
}
|
||||
|
||||
$category = $tournament['category'];
|
||||
|
||||
if ($sport_id == 5) {
|
||||
$country_id = 470;
|
||||
} else {
|
||||
|
||||
/**
|
||||
* CATEGORY
|
||||
*/
|
||||
$find = [
|
||||
'Amateur',
|
||||
'Bosnia & Herzegovina',
|
||||
'Czechia',
|
||||
'DR Congo',
|
||||
'Netherlands',
|
||||
'North & Central America',
|
||||
'Bonaire',
|
||||
'Sao Tome and Principe',
|
||||
'Cape Verde',
|
||||
'Macao',
|
||||
'Saint Kitts and Nevis',
|
||||
'Eswatini',
|
||||
'Timor Leste',
|
||||
'Laos',
|
||||
'Congo Republic',
|
||||
|
||||
];
|
||||
$replace = [
|
||||
'',
|
||||
'Bosnia Herzegovina',
|
||||
'Czech Republic',
|
||||
'Congo DR',
|
||||
'Holland',
|
||||
'North America',
|
||||
'Bonaire, Sint Eustatius and Saba',
|
||||
'Sao Tome e Principe',
|
||||
'Cape Verde Islands',
|
||||
'Macau',
|
||||
'St. Kitts and Nevis',
|
||||
'Swaziland',
|
||||
'East Timor',
|
||||
'Lao Peoples\'s Democratic Republic',
|
||||
'Congo DR',
|
||||
];
|
||||
$country_id = Country::where('name', trim(str_replace($find, $replace, $category['name'])))->value('id');
|
||||
}
|
||||
|
||||
// dd($category, $country_id);
|
||||
|
||||
if (! $country_id) {
|
||||
// platzhalter fix later sofa_score_categories => txodds countries
|
||||
// CATEGORY find <-> replace
|
||||
Log::channel('sofascore')->info($tournament);
|
||||
|
||||
$sofa_score_categorie_id = 10000000;
|
||||
} else {
|
||||
$call = SofaScoreCategorie::updateOrCreate([
|
||||
'id' => (int) $category['id'],
|
||||
'country_id' => (int) $country_id,
|
||||
'slug' => $category['slug'],
|
||||
], [
|
||||
'name' => $category['name'],
|
||||
]);
|
||||
|
||||
$sofa_score_categorie_id = $call->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* TOURNAMENT
|
||||
*/
|
||||
SofaScoreTournament::updateOrCreate([
|
||||
'sport_id' => (int) $sport_id,
|
||||
'tournament_id' => (int) $tournament['id'],
|
||||
'sofa_score_categorie_id' => (int) $sofa_score_categorie_id,
|
||||
], [
|
||||
'name' => $tournament['name'],
|
||||
'slug' => $tournament['slug'],
|
||||
]);
|
||||
$tournaments_counter++;
|
||||
|
||||
/**
|
||||
* DAY TOURNAMENT
|
||||
*/
|
||||
|
||||
SofaScoreDayTournament::updateOrCreate([
|
||||
'tournament_id' => (int) $tournament['id'],
|
||||
'day' => $day,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
Notice::note("tournaments: $tournaments_counter", 'p');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Notice::note('Archive created', 'g', 1);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore\Specials;
|
||||
|
||||
use App\Models\SofaScoreTournament;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LeaguesToLocal
|
||||
{
|
||||
public static function run()
|
||||
{
|
||||
$tornaments = DB::connection('remote_mariadb')->table('sofa_score_tournaments')->where('enabled', 1)->pluck('id');
|
||||
|
||||
SofaScoreTournament::query()->update(['enabled' => 0]);
|
||||
|
||||
foreach ($tornaments as $tornament_id) {
|
||||
SofaScoreTournament::where('id', $tornament_id)->update(['enabled' => 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore\Specials;
|
||||
|
||||
use App\Models\SofaScoreTask;
|
||||
use App\Models\SofaScoreTaskTournament;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SettingsToLocal
|
||||
{
|
||||
public static function run()
|
||||
{
|
||||
SofaScoreTask::truncate();
|
||||
$rows = DB::connection('remote_mariadb')->table('sofa_score_tasks')->get();
|
||||
foreach ($rows as $row) {
|
||||
SofaScoreTask::insert((array) $row);
|
||||
}
|
||||
|
||||
SofaScoreTaskTournament::truncate();
|
||||
$rows = DB::connection('remote_mariadb')->table('sofa_score_task_tournaments')->get();
|
||||
foreach ($rows as $row) {
|
||||
SofaScoreTaskTournament::insert((array) $row);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,38 +3,85 @@
|
||||
namespace App\Console\Commands\Grapper\Sofascore\Tools;
|
||||
|
||||
use App\Console\Commands\Nuh;
|
||||
use App\Models\SofaScoreDay;
|
||||
use App\Models\SofaScoreTask;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* FIFA World Cup 16
|
||||
* China Super League 649
|
||||
* Veikkausliiga 41
|
||||
*/
|
||||
|
||||
class LoadDays
|
||||
{
|
||||
public static function load()
|
||||
{
|
||||
$today = Nuh::$options['t'] ?? 0;
|
||||
|
||||
$yesterday = Nuh::$options['y'] ?? 0;
|
||||
$sport_id = Nuh::$options['sport_id'];
|
||||
|
||||
if($today){
|
||||
$days[] = Carbon::now()->format('Y-m-d');
|
||||
return [Carbon::now()->format('Y-m-d')];
|
||||
}
|
||||
else if($yesterday){
|
||||
$days[] = Carbon::now()->subDay()->format('Y-m-d');
|
||||
return [Carbon::now()->subDay()->format('Y-m-d')];
|
||||
}
|
||||
else {
|
||||
$days = SofaScoreDay::where('sport_id', $sport_id)->where('enabled', 1)->pluck('day')->toArray();
|
||||
}
|
||||
|
||||
if (! $days) {
|
||||
Notice::note(__file__.PHP_EOL.'no days', 'r', 1);
|
||||
}
|
||||
$res = SofaScoreTask::with('sport')->where('is_active', 1)->get();
|
||||
$dates = [];
|
||||
foreach ($res as $row) {
|
||||
|
||||
return $days;
|
||||
switch($row->mode){
|
||||
case 'yesterday':
|
||||
$dates[] = [
|
||||
'day' => Carbon::now()->subDay()->format('Y-m-d'),
|
||||
'slug' => $row->sport->ss_slug
|
||||
];
|
||||
break;
|
||||
case 'date':
|
||||
$dates[] = [
|
||||
'day' => self::validateDate($row->day_from),
|
||||
'slug' => $row->sport->ss_slug
|
||||
];
|
||||
break;
|
||||
case 'range':
|
||||
$from = self::validateDate($row->day_from);
|
||||
$to = self::validateDate($row->day_to);
|
||||
|
||||
$from = Carbon::createFromDate($from);
|
||||
$to = Carbon::createFromDate($to);
|
||||
|
||||
$lengthdates = $from->diffInDays($to);
|
||||
|
||||
if($lengthdates < 1){
|
||||
Notice::note('wrong date start must be before end', 'r', 1);
|
||||
}
|
||||
else if($lengthdates > 60){
|
||||
Notice::note('wrong date maximal 60 dates allowed', 'r', 1);
|
||||
}
|
||||
while ($from < $to){
|
||||
$dates[] = [
|
||||
'day' => $from->format('Y-m-d'),
|
||||
'slug' => $row->sport->ss_slug
|
||||
];
|
||||
$from->addDay();
|
||||
}
|
||||
}
|
||||
|
||||
if (! $dates) {
|
||||
Notice::note(__file__.PHP_EOL.'no dates', 'r', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove when element in array is double (day and slug)
|
||||
$dates = array_unique($dates, SORT_REGULAR);
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
public static function validateDate(string $date)
|
||||
{
|
||||
if(Carbon::createFromDate($date) !== false){
|
||||
return $date;
|
||||
}
|
||||
else {
|
||||
Notice::note('Wrong date format','r', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -103,18 +103,18 @@ class SofaScoreTournamentsTable
|
||||
$query->where('sofa_score_categorie_id', $sofa_score_categorie_id);
|
||||
}
|
||||
}
|
||||
)->when(
|
||||
$data['filter-grapping'],
|
||||
function (Builder $query, $filtergrapping) {
|
||||
switch ($filtergrapping) {
|
||||
case 'active':
|
||||
$query->where('enabled', 1);
|
||||
break;
|
||||
case 'disabled':
|
||||
$query->where('enabled', 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// )->when(
|
||||
// $data['filter-grapping'],
|
||||
// function (Builder $query, $filtergrapping) {
|
||||
// switch ($filtergrapping) {
|
||||
// case 'active':
|
||||
// $query->where('enabled', 1);
|
||||
// break;
|
||||
// case 'disabled':
|
||||
// $query->where('enabled', 0);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
)->when(
|
||||
$data['filter-disabled'],
|
||||
function (Builder $query, $filterdisabled) {
|
||||
|
||||
+6
-2
@@ -1,7 +1,8 @@
|
||||
# AUTO GRAPPER SOFASCORE
|
||||
|
||||
echo "\n⚽ close all open vpn"
|
||||
killall ssh
|
||||
|
||||
# echo "\n⚽ close all open vpn"
|
||||
# killall ssh
|
||||
|
||||
# echo "\n⚽ open vpn tunnel to prod"
|
||||
# ssh -f -N -L 13306:127.0.0.1:3306 -p 58371 root@162.55.242.190
|
||||
@@ -12,6 +13,9 @@ killall ssh
|
||||
# echo "\n⚽ close tunnel"
|
||||
# killall ssh
|
||||
|
||||
echo "\n⚽ grap avilable tournaments for given day"
|
||||
php artisan nuh --d --f 73 --prc=5
|
||||
|
||||
# echo "\n⚽ grapp data sofascore"
|
||||
# php artisan nuh --d --f --y 72
|
||||
|
||||
|
||||
Reference in new issue
Block a user