Created
August 17, 2018 03:53
-
-
Save kiang/c62a3b8948e856e4a125102f8cfeb27f to your computer and use it in GitHub Desktop.
download tainan pcc data from https://pcc.g0v.ronny.tw/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$units = json_decode(file_get_contents(__DIR__ . '/unit.json'), true); | |
$tmpPath = __DIR__ . '/tmp'; | |
if(!file_exists($tmpPath)) { | |
mkdir($tmpPath, 0777, true); | |
} | |
$pagePath = $tmpPath . '/page'; | |
if(!file_exists($pagePath)) { | |
mkdir($pagePath, 0777, true); | |
} | |
$casePath = $tmpPath . '/case'; | |
if(!file_exists($casePath)) { | |
mkdir($casePath, 0777, true); | |
} | |
$url = 'https://pcc.g0v.ronny.tw/api/listbyunit?unit_id='; | |
$count = 0; | |
$hash = array(); | |
foreach($units AS $k => $v) { | |
if(substr($k, 0, 4) === '3.95') { | |
$f = $pagePath . '/' . $v . '.json'; | |
if(!file_exists($f)) { | |
file_put_contents($f, file_get_contents($url . $k)); | |
} | |
$page = json_decode(file_get_contents($f), true); | |
echo $v . ':' . count($page['records']) . "\n"; | |
continue; | |
foreach($page['records'] AS $record) { | |
$unitPath = $casePath . '/' . $k; | |
if(!file_exists($unitPath)) { | |
mkdir($unitPath, 0777); | |
} | |
$jobFile = $unitPath . '/' . $record['job_number'] . '.json'; | |
$md5 = md5($jobFile); | |
if(isset($hash[$md5])) { | |
continue; | |
} else { | |
$hash[$md5] = true; | |
} | |
if(!file_exists($jobFile)) { | |
$record['tender_api_url'] = str_replace('?unit=', '?unit_id=', $record['tender_api_url']); | |
file_put_contents($jobFile, file_get_contents($record['tender_api_url'])); | |
} | |
$job = json_decode(file_get_contents($jobFile), true); | |
$item = array_pop($job['records']); | |
$itemTime = strtotime($item['date']); | |
if(false === strpos($item['brief']['title'], '合同')) { | |
continue; | |
} | |
echo date('Y-m-d', $itemTime); | |
echo "[{$item['brief']['type']}]{$item['date']} - {$item['brief']['title']}\n"; | |
echo "\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment