#!/usr/bin/php <?php /** * This is the bootstrapping code for the bot. Start in a screen to keep it running * for extended periods of time. * * @author mr-sk aka sk <*****@*****.**> * @package Botcoin * @copyright None yo, just keep this header in place! * @example ./run.php >> /dev/null * * @see config.ini * @see Botcoin.php */ require_once 'config.ini'; require_once 'Botcoin.php'; $p = new Botcoin(parse_ini_file('config.ini')); $p->run();
/** * First we check if we've attempted to make a request w/in the time limit for Bitcoincharts. * If so, return stale data. * * If we haven't made a request, or $_btcCurrencyStr is null (only on first run), we attempt * to make a GET Requst to the bitcoincharts API. If we don't get a respone we return an error * message. * * If we get a response, we format a currency string for the channel and update the * _lastCurrencyRequest. * * @return string A currency string or an error message on failure. */ private function getCurrencyData() { // Enforce that we can't hit the Bitcoins server more than once every 15 minutes. if (time() > $this->_lastCurrencyRequest + self::bChartsWaitSec || null == self::$_btcCurrencyStr) { $currencyJSON = file_get_contents(self::btcchartsURL); if (FALSE == $currencyJSON) { return 'Error retreiving currency, try again soon.'; } $cSet = json_decode($currencyJSON); self::$_btcCurrencyStr = sprintf("USD 24h:%s 7d:%s 30d:%s", $cSet->USD->{'24h'}, $cSet->USD->{'7d'}, $cSet->USD->{'30d'}); $this->_lastCurrencyRequest = time(); return self::$_btcCurrencyStr; } return sprintf("[%ss stale] %s", time() - $this->_lastCurrencyRequest, self::$_btcCurrencyStr); }