wip countries

This commit is contained in:
salam committed 2025-08-30 08:15:10 +02:00
1 parent 641b362752
commit 1b9a65b25a
23 files changed
+127755 -27137

No files matched your search

+34 -15
View File
@@ -6,27 +6,42 @@ use App\Utilities\Notice;
class Curl
{
public static $storage_file;
public static $file;
public static function load($url)
{
self::$storage_file = app_path().'/Utilities/TestFileStorage/latest.json';
$debug = NuhBash::$options['debug'] ?? 0;
$save_to_storage = NuhBash::$options['s'] ?? 0;
$load_form_storage = NuhBash::$options['l'] ?? 0;
self::$file = app_path().'/Console/TestFiles/'.strtolower(str_replace(' ', '_', NuhBash::$options['name'])).'.'.NuhBash::$options['filetype'];
$debug = NuhBash::$options['d'] ?? 0;
$save = NuhBash::$options['s'] ?? 0;
$read = NuhBash::$options['r'] ?? 0;
if ($debug) {
Notice::note($url, 'g');
Notice::note($url);
}
if ($load_form_storage) {
$file = file_get_contents(self::$storage_file);
if ($debug) {
Notice::note('data from storage', 'b');
if ($read) {
switch (NuhBash::$options['filetype']) {
case 'xml':
return simplexml_load_file(self::$file, null, LIBXML_NOCDATA);
break;
case 'json':
$file = file_get_contents(self::$file);
return json_decode($file, true);
break;
default:
Notice::note('filetype unknown', 'r', 1);
}
if ($debug) {
Notice::note('data read local', 'b');
}
return json_decode($file, true);
}
$ch = curl_init($url);
@@ -41,12 +56,16 @@ class Curl
}
curl_close($ch);
if ($save_to_storage) {
Notice::note('data saved to local storage', 'b');
file_put_contents(self::$storage_file, $data);
if ($save) {
Notice::note('data saved', 'b');
file_put_contents(self::$file, $data);
}
return json_decode($data, true);
if (NuhBash::$options['filetype'] == 'json') {
return json_decode($data, true);
} else {
return $data;
}
}
public static function curlerrorcode($id)
@@ -0,0 +1,35 @@
<?php
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\Curl;
use App\Console\Commands\NuhBash;
use App\Models\Country;
use App\Utilities\Notice;
class Countries
{
public static function call()
{
$debug = NuhBash::$options['d'] ?? 0;
$print = NuhBash::$options['p'] ?? 0;
$url = 'https://xml2.txodds.com/feed/countries.php';
$data = Curl::load($url, $debug);
if ($print) {
Notice::note($data, '', 1);
}
$count = 0;
foreach ($data as $row) {
Country::updateOrCreate(
['txid' => (int) $row->id],
['name' => (string) $row->name, 'cc' => (string) $row->cc]
);
$count++;
}
Notice::note("$count countries processed", 'g');
}
}
@@ -1,34 +0,0 @@
<?php
namespace App\Console\Commands\Grapper\TxOdds\Fixtures;
use App\Models\Country;
class TxCountries
{
public static function get($group)
{
// "group": {
// "@attributes": {
// "id": "177425",
// "cgid": "336",
// "spid": "1",
// "cnid": "381",
// "mgid": "1373",
// "cname": "UEFA Women's Champions League"
// },
// "@text": "WFBECUP UEFA Women's Champions League > Qualifying Rounds-25"
// },
$cnid = array_column($group, 'cnid');
$cname = array_column($group, 'cname');
$country = Country::firstOrCreate(
['txid' => $cnid[0]],
['name' => $cname[0]]
);
return $cnid[0];
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Console\Commands\Grapper\TxOdds\Fixtures;
use App\Models\Country;
class TxCountry
{
public static function find($group)
{
$cnid = array_column($group, 'cnid');
$cname = array_column($group, 'cname');
$country = Country::firstOrCreate(
['txid' => $cnid[0]],
['name' => $cname[0]]
);
return $country->id;
}
}
@@ -2,18 +2,14 @@
namespace App\Console\Commands\Grapper\TxOdds\Fixtures;
use App\Console\Commands\NuhBash;
use App\Models\Liga;
class TxLigas
class TxLiga
{
public static function find($group)
public static function find($country_id, $group)
{
$debug = NuhBash::$options['debug'] ?? 0;
$cname = array_column($group, 'cname');
$spid = array_column($group, 'spid');
$country_id = TxCountries::get($group);
$cgid = array_column($group, 'cgid');
$liga = Liga::firstOrCreate([
@@ -24,6 +20,5 @@ class TxLigas
]);
return $liga->id;
}
}
@@ -3,11 +3,13 @@
namespace App\Console\Commands\Grapper\TxOdds;
use App\Console\Commands\Curl;
use App\Console\Commands\Grapper\TxOdds\Fixtures\TxCountry;
use App\Console\Commands\Grapper\TxOdds\Fixtures\TxElement;
use App\Console\Commands\Grapper\TxOdds\Fixtures\TxLigas;
use App\Console\Commands\Grapper\TxOdds\Fixtures\TxLiga;
use App\Console\Commands\NuhBash;
use App\Models\Event;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
class FixturesSoccer
{
@@ -15,13 +17,18 @@ class FixturesSoccer
{
$debug = NuhBash::$options['d'] ?? 0;
$print = NuhBash::$options['p'] ?? 0;
$read = NuhBash::$options['r'] ?? 0;
$break = NuhBash::$options['b'] ?? 0;
$total = 0;
for ($i = 0; $i < 30; $i++) {
$str1 = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + $i, date('Y')));
$str2 = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 1 + $i, date('Y')));
$date = Carbon::now();
$url = 'https://xml2.txodds.com/feed/result/xml.php?ident=betaid1&passwd='.config('nuh.txodds_token')."&date=$str1,$str2&json=2";
for ($i = 0; $i < 30; $i++) {
$from = $date->addDays($i)->toDateString();
$to = $date->addDays($i + 1)->toDateString();
$url = 'https://xml2.txodds.com/feed/result/xml.php?ident=betaid1&passwd='.config('nuh.txodds_token')."&date=$from,$to&json=2";
$data = Curl::load($url, $debug);
if ($print) {
@@ -30,26 +37,32 @@ class FixturesSoccer
$count = 0;
foreach ($data['match'] as $row) {
$count++;
$txodds_id = array_column($row, 'id');
$spid = array_column($row['group'], 'spid');
$liga_id = TxLigas::find($row['group']);
$country_id = TxCountry::find($row['group']);
$liga_id = TxLiga::find($country_id, $row['group']);
$home_id = TxElement::find($row['hteam'], 1);
$away_id = TxElement::find($row['ateam'], 1);
$event = Event::firstOrCreate([
$event = Event::updateOrCreate([
'starttime' => date('Y-m-d H:i:s', strtotime($row['time'])),
'sport_id' => (int) $spid[0],
'provider_id' => 1,
'txodds_id' => (int) $txodds_id,
'liga_id' => $liga_id,
'home_id' => $home_id,
'away_id' => $away_id,
'txodds_id' => (int) $txodds_id[0],
'country_id' => (int) $country_id,
'liga_id' => (int) $liga_id,
'home_id' => (int) $home_id,
'away_id' => (int) $away_id,
]);
// dd($event);
}
Notice::note("$str1 - $count events processed", 'g');
Notice::note("$from - $count events processed", 'g');
$total += $count;
if ($break) {
break;
}
}
Notice::note("Total - $total events processed", 'g');
}
@@ -2,6 +2,7 @@
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\TxOdds\Countries;
use App\Console\Commands\Grapper\TxOdds\FixturesSoccer;
use App\Console\Commands\NuhBash;
@@ -18,6 +19,7 @@ class TxSwitch
FixturesSoccer::call();
break;
case 2:
Countries::call();
break;
case 3:
break;
+16 -3
View File
@@ -6,13 +6,14 @@ use App\Console\Commands\Grapper\TxSwitch;
use App\Models\Supervisor;
use App\Utilities\Notice;
use App\Utilities\Supervisorctl;
use DB;
use Illuminate\Console\Command;
class NuhBash extends Command
{
public static $options = [];
protected $signature = 'nuh {process=help} {eventid=0} {--d} {--f} {--a} {--p} {--w} {--s} {--l}';
protected $signature = 'nuh {process=help} {eventid=0} {--d} {--f} {--a} {--w} {--p} {--s} {--r} {--b}';
protected $description = 'NuhBash';
@@ -22,6 +23,7 @@ class NuhBash extends Command
self::$options['supervisor_id'] = $this->argument('process');
self::$options['event_id'] = $this->argument('eventid');
$queries = self::$options['m'] ?? 0;
if ($this->argument('process') == 'help') {
$txt = PHP_EOL;
@@ -33,12 +35,14 @@ class NuhBash extends Command
$txt .= 'List of options'.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL;
$txt .= '--d debug'.PHP_EOL;
$txt .= '--m debug queries'.PHP_EOL;
$txt .= '--f force update market'.PHP_EOL;
$txt .= '--a reload all'.PHP_EOL;
$txt .= '--w reload one week'.PHP_EOL;
$txt .= '--p print odds'.PHP_EOL;
$txt .= '--s store grapped file '.PHP_EOL;
$txt .= '--l load latest grapped file '.PHP_EOL;
$txt .= '--s store data to file '.PHP_EOL;
$txt .= '--r read data from file '.PHP_EOL;
$txt .= '--b break loop after one '.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL.PHP_EOL;
$txt .= 'List of supervisors'.PHP_EOL;
$txt .= '----------------------------------------------'.PHP_EOL;
@@ -49,6 +53,10 @@ class NuhBash extends Command
Notice::note($txt, 'b', 1);
}
if ($queries) {
DB::enableQueryLog();
}
Supervisorctl::start(self::$options);
switch (self::$options['type']) {
@@ -74,5 +82,10 @@ class NuhBash extends Command
}
Supervisorctl::end(self::$options);
if ($queries) {
Notice::db(DB::getQueryLog());
}
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -6,7 +6,6 @@ use App\Models\Liga;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
@@ -23,16 +22,13 @@ class EventsTable
return $record->sport->icon;
}),
TextColumn::make('starttime')->dateTime('M j, Y H:i')->sortable(),
// IconColumn::make('liga_id')->label('Flag')
// ->icon(fn (string $state): Heroicon => match ($state) {
// default => Heroicon::OutlinedPencil,
// // return Liga::where('id', $state)->value('country.icon')->first();
// }),
TextColumn::make('liga.country.name'),
// TextColumn::make('liga.name')->searchable()
// ->icon(fn (string $record): string => match ($record) {
// default => $record->liga->country->icon
// }),
IconColumn::make('country_id')
->label('Flag')
->icon(function ($record): string {
return $record->country->icon;
}),
TextColumn::make('country.name'),
TextColumn::make('liga.name'),
TextColumn::make('home.name')->searchable(),
TextColumn::make('away.name')->searchable(),
// TextColumn::make('prid')
@@ -8,12 +8,15 @@ use App\Models\Country;
use BackedEnum;
use Filament\Actions\EditAction;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Enums\IconSize;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use UnitEnum;
class CountryResource extends Resource
@@ -34,13 +37,14 @@ class CountryResource extends Resource
{
return $schema
->components([
TextInput::make('name')->required()->maxLength(255)->copyable(),
TextInput::make('icon')->maxLength(255),
TextInput::make('name')->required(),
TextInput::make('icon'),
TextInput::make('iso2')->maxLength(2),
TextInput::make('iso3')->maxLength(2),
TextInput::make('cc')->maxLength(2),
TextInput::make('numeric')->maxLength(2),
TextInput::make('txid')->maxLength(4),
TextInput::make('iso3')->maxLength(3),
TextInput::make('cc'),
TextInput::make('numeric'),
TextInput::make('txid'),
Toggle::make('other'),
]);
}
@@ -49,6 +53,7 @@ class CountryResource extends Resource
return $table
->recordTitleAttribute('name')
->columns([
TextColumn::make('id')->searchable(),
IconColumn::make('icon')
->sortable()
->icon(function ($state): string {
@@ -63,12 +68,15 @@ class CountryResource extends Resource
TextColumn::make('iso3'),
TextColumn::make('cc'),
TextColumn::make('numeric'),
TextColumn::make('txid'),
TextColumn::make('txid')->searchable(),
TextColumn::make('other'),
])
->defaultSort('name', direction: 'asc')
->filters([
//
Filter::make('icon')
->label('Missing Icons')
->query(fn (Builder $query): Builder => $query->whereNull('icon')),
])
->recordActions([
EditAction::make(),
@@ -27,6 +27,14 @@ class SupervisorForm
])
->default('Grapper')
->selectablePlaceholder(false),
Select::make('filetype')
->label('File Type')
->options([
'json' => 'json',
'xml' => 'xml',
])
->default('json')
->selectablePlaceholder(false),
Select::make('provider_id')
->relationship('provider', 'name')
->required()
@@ -39,6 +39,7 @@ class SupervisorsTable
TextColumn::make('runtime'),
TextColumn::make('lastcall'),
IconColumn::make('is_cron')->boolean()->label('Cron')->falseColor('gray'),
TextColumn::make('filetype')->badge()->alignCenter(),
TextColumn::make('created_at')
->dateTime()
->sortable()
+1 -1
View File
@@ -14,6 +14,6 @@ class Country extends Model
'cc',
'numeric',
'txid',
'tx_only',
'other',
];
}
+19 -13
View File
@@ -9,6 +9,10 @@ class Event extends Model
protected $fillable = [
'starttime',
'sport_id',
'country_id',
'liga_id',
'home_id',
'away_id',
'provider_id',
'txodds_id',
'betaid_id',
@@ -17,11 +21,23 @@ class Event extends Model
'magken_id',
'lognig_id',
'logcol_id',
'liga_id',
'home_id',
'away_id',
];
public function sport()
{
return $this->belongsTo(Sport::class);
}
public function country()
{
return $this->belongsTo(Country::class);
}
public function liga()
{
return $this->belongsTo(Liga::class);
}
public function home()
{
return $this->belongsTo(Element::class);
@@ -31,14 +47,4 @@ class Event extends Model
{
return $this->belongsTo(Element::class);
}
public function sport()
{
return $this->belongsTo(Sport::class);
}
public function liga()
{
return $this->belongsTo(Liga::class);
}
}
+16
View File
@@ -6,6 +6,22 @@ class Notice
{
// note
public static function db($message, $exit = false)
{
echo "\e[0;35m";
echo PHP_EOL.'-----------------------------------------------------------'.PHP_EOL;
if (is_array($message)) {
print_r($message);
} else {
echo $message.PHP_EOL;
}
echo '-----------------------------------------------------------'.PHP_EOL;
echo "\e[0;39m";
if ($exit) {
exit();
}
}
public static function note($message, $color = '', $exit = false)
{
switch ($color) {
File diff suppressed because it is too large. Load diff