示例#1
0
 public static function getStops()
 {
     if (is_null(self::$_stops)) {
         $doc = new DOMDocument();
         $doc->loadHtml("<html><table></table>" . self::getBody("http://www.cwb.gov.tw/V7/climate/30day/30day.php") . "</html>");
         self::$_stops = array();
         foreach ($doc->getElementById('st')->getElementsByTagName('option') as $option_dom) {
             self::$_stops[$option_dom->getAttribute('value')] = $option_dom->nodeValue;
         }
         unset($doc);
     }
     return self::$_stops;
 }
示例#2
0
        if (!$column_added) {
            fputcsv($fp, $columns);
            $column_added = true;
        }
        foreach ($values as $v) {
            fputcsv($fp, $v);
        }
    }
    $upload_id = SheetHubTool::uploadToSheetHub($fp, 'csv');
    $ret = SheetHubTool::updateFile('opendata.cwb.gov.tw', '測站觀測資料', $upload_id);
    $new_meta = $sheet_info->sheet->meta;
    $new_meta->updated_time = date('Y/m/d', $data_time);
    SheetHubTool::setMeta('opendata.cwb.gov.tw', '測站觀測資料', $new_meta);
}
// 每分鐘抓當下 15 分鐘資料
list($columns, $values) = CWB::getAll15mInfo();
$fp = tmpfile();
fputcsv($fp, $columns);
foreach ($values as $v) {
    fputcsv($fp, $v);
}
$upload_id = SheetHubTool::uploadToSheetHub($fp, 'csv');
$sheet = '測站觀測資料_15分鐘_' . date('Y_m');
try {
    $sheet_info = SheetHubTool::getSheetHubInfo('opendata.cwb.gov.tw', $sheet);
    $ret = SheetHubTool::updateFile('opendata.cwb.gov.tw', $sheet, $upload_id);
    error_log("done, insert: " . count($ret->insert) . ', update: ' . count($ret->update) . ', delete: ' . count($ret->delete));
} catch (Exception $e) {
    SheetHubTool::newFile('opendata.cwb.gov.tw', $sheet, $upload_id, array());
    SheetHubTool::setURIColumns('opendata.cwb.gov.tw', $sheet, array(0, 2));
}