Move colorcli class to helpers

This commit is contained in:
DariusIII
2025-12-26 23:48:37 +01:00
parent ed202f0f9e
commit f50875550d
90 changed files with 1129 additions and 1296 deletions
+6 -6
View File
@@ -5,28 +5,28 @@
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Services\GamesService;
use Blacklight\ColorCLI;
use Illuminate\Support\Facades\DB;
$pdo = DB::connection()->getPdo();
$game = new GamesService;
$colorCli = new ColorCLI;
$res = $pdo->query(
sprintf('SELECT id, title FROM gamesinfo WHERE cover = 0 ORDER BY id DESC LIMIT 100')
);
$total = $res->rowCount();
if ($total > 0) {
$colorCli->header('Updating game covers for '.number_format($total).' releases.');
cli()->header('Updating game covers for '.number_format($total).' releases.');
foreach ($res as $arr) {
$starttime = now()->timestamp;
$gameInfo = $game->parseTitle($arr['title']);
if ($gameInfo !== false) {
$colorCli->primary('Looking up: '.$gameInfo['release']);
cli()->primary('Looking up: '.$gameInfo['release']);
$gameData = $game->updateGamesInfo($gameInfo);
if ($gameData === false) {
$colorCli->primary($gameInfo['release'].' not found');
cli()->primary($gameInfo['release'].' not found');
} else {
if (file_exists(storage_path('covers/games/').$gameData.'.jpg')) {
$pdo->exec(sprintf('UPDATE gamesinfo SET cover = 1 WHERE id = %d', $arr['id']));
@@ -37,7 +37,7 @@ if ($total > 0) {
// Rate limiting - 1 per second
$diff = floor((now()->timestamp - $starttime) * 1000000);
if (1000000 - $diff > 0) {
$colorCli->alternate('Sleeping');
cli()->alternate('Sleeping');
usleep(1000000 - $diff);
}
}