/** * insert college=>lesson one type pages info(no include lesson=>student pages info). * @param $term_no. * @param $log_mode 1(output nots) 0(not output). * notice:local server should already have the web code file(college_lesson file). * use the function in spider.func.php to get them first. */ function insert_college_lesson_in_term($term_no, $log_mode = '1') { require_once ROOT_PATH . "\\Spider\\include\\inc.php"; require_once ROOT_PATH . "\\Spider\\include\\spider.func.php"; require_once ROOT_PATH . "\\Spider\\class\\db\\lesson_spider_db.php"; $db = new cDatabase(DATABASE_INFO_CONSTANTS::$db_info); $college_lesson_db = new college_lesson_spider_db($db); //注意这里如果没有关闭的话,后面会出现错误 $log = new myLog(); $log->setMode($log_mode); foreach ($college_list as $college) { $filepl = "resource/college_%s/%s.txt"; $file = sprintf($filepl, $term_no, $college); $code = file_get_contents($file); $mode = array(FIRST => "tr", SECOND => "td", LAST => ""); $list = get_attr_lists($code, $mode); //print_r($list); $row_count = count($list[0]); $col = 0; $col_count = count($list); $log->add(__FILE__ . ":open " . $college . ".txt"); for ($col = 0; $col < $col_count; $col++) { if ($col == 0) { continue; } if ($col >= $col_count - 1) { //echo "<br>"; break; } //将数据保存到数据库中 $mylist = $college_lesson_list; $mylist[id] = $list[$col][id]; $mylist[college] = $list[$col][college]; $mylist[teacher] = $list[$col][teacher]; $mylist[lesson_time] = $list[$col][lesson_time]; $mylist[major_class] = $list[$col][major_class]; $mylist[lesson_no] = $list[$col][lesson_no]; $mylist[lesson_name] = $list[$col][lesson_name]; $mylist[credit] = $list[$col][credit]; $mylist[total_person] = $list[$col][total_person]; $mylist[limit_person] = $list[$col][limit_person]; $mylist[lesson_type] = $list[$col][lesson_type]; $mylist[weeks] = $list[$col][weeks]; $mylist[room] = $list[$col][room]; $mylist[credit_type] = $list[$col][credit_type]; $mylist[other] = $list[$col][other]; $mylist[term_no] = $term_no; $college_lesson_db->insert_all($mylist); } } }
$this->saveFile('<div style="color:#f00">' . $mess . '</div>'); } public function viewSucc($mess) { $this->saveFile('<div style="color:#0F0">' . $mess . '</div>'); } public function __construct($file = 'myLog.txt', $pathInRoot = '/analiz/') { if (file_exists($_SERVER['DOCUMENT_ROOT'] . $pathInRoot . $file)) { $this->fileName = $_SERVER['DOCUMENT_ROOT'] . $pathInRoot . $file; } else { echo '[myLog]Not Found Log File'; } } } $myLog = new myLog(); $myLog->viewSucc('Start part #' . $i); $i = $_POST['step']; $sourceFile = 'p_' . $i . '_new_xml_offers.csv'; ini_set('max_execution_time', 7200); $fileJob = $pathToFolderFile . $sourceFile; if (!file_exists($fileJob)) { echo "not found file {$fileJob}<br />"; die; } $f = fopen($fileJob, "r"); while (!feof($f)) { $string = fgets($f); $string = trim($string); $string .= ';'; $string = iconv('windows-1251', 'UTF-8', $string);