<?php |
<?php |
include_once ("../lib/common.inc.php"); |
include_once ("../lib/common.inc.php"); |
// to reset: update agency set abn = 0, website = '' |
// to reset: update agency set abn = 0, website = '' |
$ch = curl_init(); |
$ch = curl_init(); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
curl_setopt($ch, CURLOPT_REFERER, "http://contractdashboard.lambdacomplex.org"); |
curl_setopt($ch, CURLOPT_REFERER, "http://contractdashboard.lambdacomplex.org"); |
$querySel = sprintf("SELECT * FROM `agency` where ABN = 0 OR website = ''"); |
$querySel = sprintf("SELECT * FROM `agency` where ABN = 0 OR website = ''"); |
$resultSel = mysql_query($querySel); |
$resultSel = mysql_query($querySel); |
while ($row = mysql_fetch_array($resultSel, MYSQL_ASSOC)) { |
while ($row = mysql_fetch_array($resultSel, MYSQL_ASSOC)) { |
$agency = $row['agencyName']; |
$agency = $row['agencyName']; |
//foreach $agency |
//foreach $agency |
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=ABQIAAAA95XYXN0cki3Yj_Sb71CFvBSgIPe2k9-DRgEVQvbvQDV8xmTiXRTBpHxrD7bSh5rl2lswY56769CyQQ&rsz=small&filter=1&gl=au&q=" . urlencode($agency) . "%20ABN%20site:.gov.au%20-site:www.abr.business.gov.au"; |
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=ABQIAAAA95XYXN0cki3Yj_Sb71CFvBSgIPe2k9-DRgEVQvbvQDV8xmTiXRTBpHxrD7bSh5rl2lswY56769CyQQ&rsz=small&filter=1&gl=au&q=" . urlencode($agency) . "%20ABN%20site:.gov.au%20-site:www.abr.business.gov.au"; |
curl_setopt($ch, CURLOPT_URL, $url); |
curl_setopt($ch, CURLOPT_URL, $url); |
$body = curl_exec($ch); |
$body = curl_exec($ch); |
$json = json_decode($body); |
$json = json_decode($body); |
echo "<pre>"; |
echo "<pre>"; |
$result = $json->responseData->results[0]; |
$result = $json->responseData->results[0]; |
print_r($result); |
print_r($result); |
echo "</pre>"; |
echo "</pre>"; |
echo "<b> Agency:</b> $agency"; |
echo "<b> Agency:</b> $agency"; |
echo "<b> URL:</b> http://" . $result->visibleUrl; |
echo "<b> URL:</b> http://" . $result->visibleUrl; |
preg_match('/\d{2} \d{3} \d{3} \d{3}/i', $result->content, $abn); |
preg_match('/\d{2} \d{3} \d{3} \d{3}/i', $result->content, $abn); |
$abn[0] = str_replace(" ","",$abn[0]); |
$abn[0] = str_replace(" ","",$abn[0]); |
echo "<b> ABN:</b> {$abn[0]}"; |
echo "<b> ABN:</b> {$abn[0]}"; |
if ($abn[0] > 1000) { |
if ($abn[0] > 1000) { |
$result = mysql_query("UPDATE agency SET website = 'http://" . $result->visibleUrl . "', abn = '{$abn[0]}' WHERE agencyName = '$agency';"); |
$result = mysql_query("UPDATE agency SET website = 'http://" . $result->visibleUrl . "', abn = '{$abn[0]}' WHERE agencyName = '$agency';"); |
if ($result) echo $agency . " set in " . mysql_affected_rows() . " <br>\n"; |
if ($result) echo $agency . " set in " . mysql_affected_rows() . " <br>\n"; |
} else { |
} else { |
echo "invalid ABN"; |
echo "invalid ABN"; |
$result = mysql_query("UPDATE agency SET website = 'http://" . $result->visibleUrl . "' WHERE agencyName = '$agency';"); |
$result = mysql_query("UPDATE agency SET website = 'http://" . $result->visibleUrl . "' WHERE agencyName = '$agency';"); |
if ($result) echo $agency . " set in " . mysql_affected_rows() . " <br>\n"; |
if ($result) echo $agency . " set in " . mysql_affected_rows() . " <br>\n"; |
} |
} |
// fi |
// fi |
|
|
} |
} |
curl_close($ch); |
curl_close($ch); |
?> |
?> |