Пример #1
0
function error($message)
{
    echo "<html><script>alert(" . json_encode($message) . "); document.location=document.location;</script></html>";
    exit;
}
if ($_POST['url']) {
    if (!filter_var($_POST['url'], FILTER_VALIDATE_URL)) {
        error("不是合法的網址");
        exit;
    }
    include __DIR__ . '/DataGovTw.php';
    $d = new DataGovTw();
    try {
        $portal_meta = $d->getMetaFromPortal($_POST['url']);
        $config = array('source' => $_POST['url'], 'period' => 0);
        $m = $d->updateOrInsert(str_replace('/', '_', $portal_meta['title']), $config);
    } catch (Exception $e) {
        error("匯入失敗,原因: " . $e->getMessage());
        exit;
    }
    error("匯入完成," . $m);
    exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>data.gov.tw importer</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap.css">
Пример #2
0
<?php

include 'DataGovTw.php';
$d = new DataGovTw();
if ($argv = $_SERVER['argv'][1]) {
    if (filter_var($argv, FILTER_VALIDATE_URL)) {
        // 網址就直接抓下來傳傳看
        $portal_meta = $d->getMetaFromPortal($argv);
        $config = array('source' => $argv);
        if ($_SERVER['argv'][2]) {
            $config['meta_only'] = true;
        }
        $config['force'] = true;
        $d->updateOrInsert(str_replace('/', '_', $portal_meta['title']), $config);
    } else {
        $d->updateOrInsert($argv, array());
    }
} else {
    $url = 'https://sheethub.com/data.gov.tw/?format=json';
    while ($url) {
        $sheets = json_decode(file_get_contents($url));
        foreach ($sheets->data as $sheet_info) {
            if ($sheet_info->meta->update_code != 'https://github.com/sheethub/data-import-script/blob/master/data.gov.tw/update.php') {
                continue;
            }
            $d->updateOrInsert($sheet_info->name, array('sheet_info' => $sheet_info));
        }
        $url = $sheets->next_url;
    }
}