Esempio n. 1
0
    public function main()
    {
        $list = array('StopLocation' => array('period' => 86400), 'CarUnusual' => array('period' => 0), 'Parameter' => array('period' => 86400), 'IStop' => array('period' => 86400), 'IStopPath' => array('period' => 86400), 'Stop' => array('period' => 86400), 'Provider' => array('period' => 86400), 'OrgPathAttribute' => array('period' => 86400), 'EstimateTime' => array('period' => 0), 'BusEvent' => array('period' => 0), 'BusData' => array('period' => 0), 'SemiTimeTable' => array('period' => 86400), 'TimeTable' => array('period' => 86400), 'CarInfo' => array('period' => 86400), 'PathDetail' => array('period' => 86400), 'Route' => array('period' => 86400));
        foreach ($list as $type => $config) {
            if (!($fetched_time = $this->getSheetHubInfo($type)->sheet->meta->fetched_time)) {
                //throw new Exception("找不到原來的更新時間");
            }
            if (time() - strtotime($fetched_time) < $config['period']) {
                continue;
            }
            $time = microtime(true);
            error_log("Type={$type} downloading");
            list($fp, $updatetime) = $this->getFileFrom5284($type);
            $delta = microtime(true) - $time;
            $time = microtime(true);
            error_log("Type={$type} downloaded, spent {$delta}, uploading");
            $upload_id = $this->uploadToSheetHub($fp);
            $delta = microtime(true) - $time;
            $time = microtime(true);
            error_log("Type={$type} uploaded, spent {$delta}, updating");
            $ret = $this->updateFile($type, $upload_id);
            $delta = microtime(true) - $time;
            $time = microtime(true);
            error_log("Type={$type} updated, spent {$delta}, insert: " . count($ret->insert) . ', update: ' . count($ret->update) . ', delete: ' . count($ret->delete));
            $this->setMeta($type, array('updated_time' => $updatetime, 'fetched_time' => date('c', time()), 'period' => $config['period'] == 86400 ? '每日' : '每分鐘', 'source' => 'http://www.dot.gov.taipei/', 'update_code' => 'https://github.com/sheethub/data-import-script/blob/master/5284.taipei.gov.tw/update.php'));
        }
    }
}
$u = new Updater();
$u->main();
                rename(stream_get_meta_data($download_fp)['uri'], $target_file);
            }
            $cmd = "node " . escapeshellarg(__DIR__ . '/geojson_parse.js') . " get_type " . escapeshellarg($target_file);
            exec($cmd, $outputs, $ret);
            if ($ret) {
                throw new Exception("取得 {$file_url} JSON 格式錯誤: " . $ret->message);
            }
        }
    }
    public function main($argv)
    {
        $fp = fopen(__DIR__ . '/../geo.csv', 'r');
        $fp_new = fopen(__DIR__ . '/../geo_new.csv', 'w');
        $columns = fgetcsv($fp);
        fputcsv($fp_new, $columns);
        while ($row = fgetcsv($fp)) {
            list($folder, $name, $url, $srs, $origin_encoding, $updated_at) = $row;
            $info = $this->getInfoFromURL($url);
            if ($updated_at != $info->updated_at) {
                $this->downloadFromURL($info->link, $folder, $srs, $origin_encoding);
                $updated_at = $info->updated_at;
            }
            fputcsv($fp_new, array($folder, $name, $url, $srs, $origin_encoding, $updated_at));
        }
        fclose($fp_new);
        rename(__DIR__ . '/../geo_new.csv', __DIR__ . '/../geo.csv');
    }
}
$u = new Updater();
$u->main($_SERVER['argv']);