mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-09-04 21:05:14 +00:00
coindb: allow to grab bittrex icons
This commit is contained in:
parent
cf9a3b75bd
commit
0862ff66a9
2 changed files with 58 additions and 1 deletions
|
@ -90,7 +90,10 @@ void db_add_user(YAAMP_DB *db, YAAMP_CLIENT *client)
|
|||
}
|
||||
|
||||
else
|
||||
db_query(db, "UPDATE accounts SET coinsymbol='%s', donation=%d WHERE id=%d AND balance=0", symbol, gift, client->userid);
|
||||
db_query(db, "UPDATE accounts SET coinsymbol='%s', donation=%d WHERE id=%d AND balance = 0"
|
||||
" AND (SELECT COUNT(id) FROM payouts WHERE account_id=%d AND tx IS NULL) = 0" // failed balance
|
||||
" AND (SELECT pending FROM balanceuser WHERE userid=%d ORDER by time DESC LIMIT 1) = 0" // pending balance
|
||||
, symbol, gift, client->userid, client->userid, client->userid);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -53,6 +53,7 @@ class CoindbCommand extends CConsoleCommand
|
|||
$nbUpdated = $this->grabBterIcons();
|
||||
$nbUpdated += $this->grabCcexIcons();
|
||||
$nbUpdated += $this->grabCryptopiaIcons();
|
||||
$nbUpdated += $this->grabBittrexIcons(); // can be huge ones
|
||||
$nbUpdated += $this->grabCoinExchangeIcons();
|
||||
$nbUpdated += $this->grabAlcurexIcons();
|
||||
$nbUpdated += $this->grabNovaIcons();
|
||||
|
@ -295,6 +296,59 @@ class CoindbCommand extends CConsoleCommand
|
|||
return $nbUpdated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Icon grabber - Bittrex
|
||||
*/
|
||||
public function grabBittrexIcons()
|
||||
{
|
||||
$nbUpdated = 0;
|
||||
$markets = bittrex_api_query('public/getmarkets');
|
||||
if (!is_object($markets) || !is_object($markets->result)) {
|
||||
echo "bittrex api error\n";
|
||||
return $nbUpdated;
|
||||
}
|
||||
$sql = "SELECT DISTINCT coins.id FROM coins INNER JOIN markets M ON M.coinid = coins.id WHERE M.name='bittrex' AND IFNULL(coins.image,'') = ''";
|
||||
$coins = dbolist($sql);
|
||||
if (empty($coins))
|
||||
return $nbUpdated;
|
||||
echo "bittrex: try to download new icons...\n";
|
||||
foreach ($coins as $coin) {
|
||||
$coin = getdbo('db_coins', $coin["id"]);
|
||||
$symbol = $coin->symbol;
|
||||
if (!empty($coin->symbol2)) $symbol = $coin->symbol2;
|
||||
$local = $this->basePath."/images/coin-{$symbol}.png";
|
||||
$url = '';
|
||||
foreach ($markets->result as $m) {
|
||||
if ($m->MarketCurrency == $symbol) {
|
||||
$url = $m->LogoUrl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (empty($url)) continue;
|
||||
try {
|
||||
$data = @ file_get_contents($url);
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
if (strlen($data) < 2048) continue;
|
||||
file_put_contents($local, $data);
|
||||
$size = filesize($local);
|
||||
if ($size > 0) {
|
||||
if ($size > 100*1024) {
|
||||
echo "warning: $symbol icon is huge, ".round($size/1024,1)." KB ($url)\n";
|
||||
unlink($local);
|
||||
} else {
|
||||
echo $symbol." icon found\n";
|
||||
$coin->image = "/images/coin-{$symbol}.png";
|
||||
$nbUpdated += $coin->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($nbUpdated)
|
||||
echo "$nbUpdated icons downloaded from bittrex\n";
|
||||
return $nbUpdated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Icon grabber - Ccex
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue