public static function updateRate() { //日志文件 self::$log = new Log(LOG_PATH, __FILE__); //临时文件 self::$tmp = new Tmp(TMP_PATH); self::$tmp->addTmp('rate.step.time', false); self::$log->debugLog("Begin Update Rate"); echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body>'; $lastTime = self::$tmp->getTmpContent('rate.step.time'); //校验上次更新时间 $pattern = "/[0-9]{4}-[0-9]{2}-[0-9]{2}/"; preg_match($pattern, $lastTime, $k); $lastTime = $k[0]; if (!$lastTime) { self::$log->errorLog("Get LastTime Failed"); return 0; } $thisTime = date("Y-m-d", strtotime('-1 day')); $page = 0; $list = array(); while ($page < 4188) { $page++; $url = "http://yanbao.stock.hexun.com/xgq/gsyj.aspx?1=1&page=" . $page; self::$log->debugLog('Get Url', $url); $html = RateKeeper::fetchSinglePage($url); self::$log->debugLog("Fetch Url Page Success"); $updata = RateKeeper::parseRateHtml($html); if ($updata) { $list = array_merge($updata, $list); } if ($list[0][1]['time'] <= $lastTime) { break; } } if ($list) { //var_dump($list); foreach ($list as $new) { $rd = new RateData($new[0]); $data = $rd->getRateData(); if (!$data) { RateKeeper::addRate($rd->getDataFile(), array($new[1])); self::$log->noticeLog("Update", $new[0], $new[1]['time'], $new[1]['title'], "Success"); continue; } //echo $new[1]['time']. '>'. $t. '<br />'; if ($new[1]['time'] > $lastTime && $new[1]['time'] <= $thisTime) { RateKeeper::addRate($rd->getDataFile(), array($new[1])); self::$log->noticeLog("Update", $new[0], $new[1]['time'], $new[1]['title'], "Success"); } } } else { self::$log->errorLog("Parse Rate Failed"); } self::$tmp->newTmpFile('rate.step.time'); self::$tmp->putTmpContent('rate.step.time', $thisTime); self::$log->debugLog("Finish Update Rate"); }
public static function show() { parent::show(); $stockInfo = array(); $stockInfo["code"] = $_GET["code"]; $i = Refer::searchCode($stockInfo["code"]); if (!$i) { exit(0); } $stockInfo["name"] = $i['name']; $stockInfo["spell"] = $i['spell']; $stockInfo["period"] = null; /* * $stockInfo["period"] = array('start'=>strtotime("Thu May 28 00:00:00 +0800 2015")*1000, 'end'=>strtotime("Mon Dec 23 00:00:00 +0800 2015")*1000); */ $stockInfo["right"] = "before"; $gd = new GbbqData($stockInfo["code"]); $gbbq = $gd->getGbbqLabel(); $stockInfo['gbbq'] = $gbbq; $dd = new DdeData($stockInfo["code"]); $dde = $dd->getDdeData(); $stockInfo['dde'] = $dde; $tdd = new ThsDoctorData($stockInfo["code"]); $ths = $tdd->getThsDoctorData(); $stockInfo['ths'] = $ths; $ld = new LhbData($stockInfo["code"]); $lhb = $ld->getLhbData(); $stockInfo['lhb'] = $lhb; $rd = new RateData($stockInfo["code"]); $rate = RateData::filterBuy($rd->getRateData()); $stockInfo['rate'] = $rate; $stockInfo['day'] = array(); $typeRight = array("normal", "before", "after"); foreach ($typeRight as $aTypeRight) { $dd = new DayData($stockInfo["code"], $aTypeRight); if ($dd->prepareData()) { $stockInfo['day'][$aTypeRight] = $dd->getStockData(); } else { $stockInfo['day'][$aTypeRight] = null; } } self::setTitle($stockInfo['name'] . '(' . $stockInfo['code'] . ') - Stock -- ForeShadow (Alpha)'); self::$smarty->assign('historyUrl', Url::getBasePhp('History')); self::$smarty->assign('favoriteUrl', Url::getBasePhp('Favorite')); self::$smarty->assign('rawData', json_encode($stockInfo)); self::$smarty->display('Chart.tpl'); }