Update getGameCovers and Games

This commit is contained in:
DariusIII
2017-04-04 14:36:23 +02:00
parent 18fcd2bace
commit da9fc59196
2 changed files with 9 additions and 8 deletions
+7 -6
View File
@@ -1,9 +1,10 @@
<?php
//This script will update all records in the gamesinfo table
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');
require_once dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'bootstrap.php';
use nntmux\db\DB;
use nntmux\ColorCLI;
use nntmux\Games;
@@ -11,20 +12,20 @@ $pdo = new DB();
$game = new Games(['Echo' => true, 'Settings' => $pdo]);
$res = $pdo->query(
sprintf("SELECT id, title FROM gamesinfo WHERE cover = 0 ORDER BY id DESC LIMIT 100")
sprintf('SELECT id, title FROM gamesinfo WHERE cover = 0 ORDER BY id DESC LIMIT 100')
);
$total = count($res);
if ($total > 0) {
echo $pdo->log->header("Updating game covers for " . number_format($total) . " releases.");
echo ColorCLI::header('Updating game covers for ' . number_format($total) . ' releases.');
foreach ($res as $arr) {
$starttime = microtime(true);
$gameInfo = $game->parseTitle($arr['title']);
if ($gameInfo !== false) {
echo $pdo->log->primary('Looking up: ' . $gameInfo['release']);
echo ColorCLI::primary('Looking up: ' . $gameInfo['release']);
$gameData = $game->updateGamesInfo($gameInfo);
if ($gameData === false) {
echo $pdo->log->primary($gameInfo['release'] . ' not found');
echo ColorCLI::primary($gameInfo['release'] . ' not found');
} else {
if (file_exists(NN_COVERS . 'games' . DS . $gameData . '.jpg')) {
$pdo->queryExec(sprintf('UPDATE gamesinfo SET cover = 1 WHERE id = %d', $arr['id']));
@@ -35,7 +36,7 @@ if ($total > 0) {
// amazon limits are 1 per 1 sec
$diff = floor((microtime(true) - $starttime) * 1000000);
if (1000000 - $diff > 0) {
echo $pdo->log->alternate("Sleeping");
echo ColorCLI::alternate('Sleeping');
usleep(1000000 - $diff);
}
}