Пример #1
0
 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');
 }
Пример #2
0
 public static function updateSingleDay($item, $type)
 {
     $dd = new DayData($item['code'], $type);
     $last = $dd->getStockData();
     if (!$last) {
         self::$log->errorLog($item['name'], $item['code'], $type, "Get Exist Data Failed");
         self::$tmp->putTmpContent('day.duty.failed', join(":", $item) . "|", FILE_APPEND);
     }
     if (end($last)["time"] == self::$endDay) {
         self::$log->noticeLog($item['name'], $item['code'], $type, "Already Updated");
         return true;
     }
     //多读取10天的数据来对比 确认能否接上
     $begin = strtotime($last[sizeof($last) - 10]['time']) * 1000;
     $end = strtotime("now") * 1000;
     $url = 'https://xueqiu.com/stock/forchartk/stocklist.json?symbol=' . $item['code'] . '&period=1day&type=' . $type . '&begin=' . $begin . '&end=' . $end;
     self::$log->debugLog($item['name'], $item['code'], $type, $url);
     $json = DayKeeper::curlXueqiuJson($url, self::$tmp->getTmpFile('day.duty.cookie'));
     while (!($json = DayKeeper::parseXueqiuJson($json))) {
         $json = DayKeeper::curlXueqiuJson($url, self::$tmp->getTmpFile('day.duty.cookie'));
         sleep(1);
     }
     self::$log->debugLog($item['name'], $item['code'], $type, "Curl and Parse success");
     if ($item['code'] == Config::get('Stock.SH')) {
         self::$endDay = end($json)['time'];
     }
     //var_dump($json);
     //echo "<br/><br/><br/>";
     //var_dump(end($json));
     //整合数据
     $updata = DayKeeper::mergeUpdate($last, $json);
     //var_dump($updata);
     if ($updata !== false) {
         self::$log->debugLog($item['name'], $item['code'], $type, "Merge OK");
         DayKeeper::addDay($dd->getDataFile(), $updata);
         self::$log->noticeLog($item['name'], $item['code'], $type, "Update " . sizeof($updata) . " OK");
     } else {
         self::$log->errorLog($item['name'], $item['code'], $type, "Merge Failed");
         self::$tmp->putTmpContent('day.duty.failed', join(":", $item) . "|", FILE_APPEND);
     }
 }