Ejemplo n.º 1
0
 public static function updateGbbq()
 {
     self::$log->debugLog("Begin Update Gbbq");
     /*
     $url = "http://stockdata.stock.hexun.com/2009_fhzzgb_000001.shtml";
     $json = DayKeeper::curlXueqiuJson($url, self::$tmp->getTmpFile('day.duty.cookie'));
     $json = DayKeeper::parseXueqiuJson($json);
     var_dump($json);
     */
     $p = -1;
     $list = Refer::getStock();
     //得到进度
     $content = self::$tmp->getTmpContent('gbbq.step.process');
     $content = explode('===', $content);
     $lastProcess = $content && $content[0] ? $content[0] : -1;
     foreach ($list as $item) {
         $p++;
         //if ($p >= 3 ) break;
         if ($p < $lastProcess) {
             continue;
         }
         self::$tmp->putTmpContent('gbbq.step.process', $p . '===' . $item['code'] . ' ' . $item['name']);
         $numCode = substr($item['code'], 2);
         $url = "http://stockdata.stock.hexun.com/2009_fhzzgb_" . $numCode . ".shtml";
         self::$log->debugLog($item['name'], $item['code'], $url);
         $html = GbbqKeeper::fetchSingleGbbq($url, $numCode);
         if ($html) {
             self::$log->debugLog($item['name'], $item['code'], "Fetch Gbbq Success");
             $now = GbbqKeeper::parseGbbqHtml($html);
             if ($now) {
                 $gd = new GbbqData($item['code']);
                 $last = $gd->getGbbqData();
                 if ($last) {
                     $updata = GbbqKeeper::mergeUpdate($last, $now);
                     GbbqKeeper::addGbbq($gd->getDataFile(), $updata);
                 } else {
                     $updata = $now;
                     GbbqKeeper::putGbbq($gd->getDataFile(), $updata);
                 }
                 self::$log->noticeLog($item['name'], $item['code'], "Update Gbbq Success");
                 self::$tmp->putTmpContent('gbbq.step.success', join(":", $item) . "|", FILE_APPEND);
             } else {
                 self::$log->errorLog($item['name'], $item['code'], "Parse Gbbq Failed");
                 self::$tmp->putTmpContent('gbbq.step.failed', join(":", $item) . "|", FILE_APPEND);
             }
         } else {
             self::$log->errorLog($item['name'], $item['code'], "Fetch Gbbq Failed");
             self::$tmp->putTmpContent('gbbq.step.failed', join(":", $item) . "|", FILE_APPEND);
         }
     }
     self::$log->debugLog("Finish Update Gbbq");
     self::$tmp->putTmpContent('gbbq.step.process', '');
 }