public function main($argv) { Pix_Table::$_save_memory = true; list(, $type, $year, $month) = $argv; if (!in_array($type, array('company', 'bussiness', 'company-continue', 'bussiness-continue'))) { return $this->wrong_argv(); } if (in_array($type, array('company', 'bussiness'))) { $year = intval($year); $month = intval($month); if (!intval($year) or !intval($month)) { return $this->wrong_argv(); } } if ('company' == $type) { $ids = Crawler::crawlerMonth($year, $month); $ids = array_unique($ids); file_put_contents('ids', implode("\n", $ids)); foreach ($ids as $id) { $u = Updater::update($id); if ($u) { $u->updateSearch(); } } } elseif ('company-continue' == $type) { $ids = explode("\n", file_get_contents('ids')); $pos = array_search($year, $ids); var_dump($pos); if (false === $pos) { return $this->wrong_argv(); } foreach (array_slice($ids, $pos - 1) as $id) { $u = Updater::update($id); if ($u) { $u->updateSearch(); } } } else { $ids = Crawler::crawlerBussiness($year, $month); $ids = array_unique($ids); file_put_contents('ids', implode("\n", $ids)); foreach ($ids as $id) { $u = Updater::updateBussiness($id); if ($u) { $u->updateSearch(); } } } }
<?php include __DIR__ . '/init.php'; Pix_Table::$_save_memory = true; $last_time = intval(KeyValue::get('snapshot_at')); // dump count while (true) { $min_time = RankData::search("`time` > {$last_time}")->min('time')->time; if (!$min_time) { break; } $month_start = mktime(0, 0, 0, date('m', $min_time), 1, date('Y', $min_time)); $month_end = strtotime('+1 month', $month_start); $filename = 'ptthot-' . date('Ym', $month_start) . '.csv.gz'; $temp = tmpfile(); $meta_data = stream_get_meta_data($temp); $tmp_filename = $meta_data['uri']; $stream = gzopen($tmp_filename, 'w'); fwrite($stream, "#board,timestamp,count\n"); foreach (RankData::search("`time` >= {$month_start} AND `time` < {$month_end}")->order(array('board', 'time'))->volumemode(10000) as $rankdata) { $last_time = max($last_time, $rankdata->time); fwrite($stream, "{$rankdata->board},{$rankdata->time},{$rankdata->count}\n"); } fclose($stream); DropboxLib::putFile($tmp_filename, $filename); fclose($temp); KeyValue::set('snapshot_at', $last_time); } //dump titlehistory $filename = 'ptthot-title.csv.gz'; $temp = tmpfile();
public function testNullOrFalse() { Pix_Table::$_save_memory = false; $cache = new Pix_Table_TableCacheTest_Cache(); Pix_Table::setCache($cache); $table = Pix_Table::getTable('Pix_Table_TableCacheTest_User'); $table->enableTableCache(); // 什麼都沒有是 false $this->assertTrue($table->getRowFromCache(6) === false); // cacheRow null 後是 null (表示被刪除) $table->cacheRow(7, null); $this->assertTrue($table->getRowFromCache(7) === null); // cacheRow false 後是 false $table->cacheRow(8, false); $this->assertTrue($table->getRowFromCache(8) === false); }