示例#1
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);
     }
 }