single record scraper
[contractdashboard.git] / admin / updateUNSPSC.php
blob:a/admin/updateUNSPSC.php -> blob:b/admin/updateUNSPSC.php
<?php <?php
error_reporting(E_ALL); error_reporting(E_ALL);
include_once("../lib/common.inc.php"); include_once("../lib/common.inc.php");
$unspscresult = mysql_query ("select * from UNSPSCcategories;"); $unspscresult= $conn->prepare('select * from "UNSPSCcategories";');
while ($row = mysql_fetch_assoc($unspscresult)) { $unspscresult->execute();
  foreach ($unspscresult->fetchAll() as $row) {
$unspsc[$row['Title']] = $row['UNSPSC']; $unspsc[$row['Title']] = $row['UNSPSC'];
// some Australian spellings // some Australian spellings
$isiz = str_replace("iz","is",$row['Title']); $isiz = str_replace("iz","is",$row['Title']);
$unspsc[$isiz] = $row['UNSPSC']; $unspsc[$isiz] = $row['UNSPSC'];
$defence = str_replace("efense","efence",$row['Title']); $defence = str_replace("efense","efence",$row['Title']);
$unspsc[$defence] = $row['UNSPSC']; $unspsc[$defence] = $row['UNSPSC'];
  $armor = str_replace("rmored","rmoured",$row['Title']);
  $unspsc[$armor] = $row['UNSPSC'];
$center = str_replace("enter","entre",$row['Title']); $center = str_replace("enter","entre",$row['Title']);
$unspsc[$center] = $row['UNSPSC']; $unspsc[$center] = $row['UNSPSC'];
// some divergence from standard // some divergence from standard
$tobacco = str_replace("Food Beverage and Tobacco Products","Food and Beverage Products",$row['Title']); $tobacco = str_replace("Food Beverage and Tobacco Products","Food and Beverage Products",$row['Title']);
$unspsc[$tobacco] = $row['UNSPSC']; $unspsc[$tobacco] = $row['UNSPSC'];
$architect = str_replace("Building and Construction and Maintenance Services","Architectural services",$row['Title']); $architect = str_replace("Building and Construction and Maintenance Services","Architectural services",$row['Title']);
$unspsc[$architect] = $row['UNSPSC']; $unspsc[$architect] = $row['UNSPSC'];
// some just plain wrong // some just plain wrong
$noOilRigs = str_replace("Building and Construction and Maintenance Services","Management and provision of all facilities engineering modification and maintenance services for a site or platform",$row['Title']); $noOilRigs = str_replace("Building and Construction and Maintenance Services","Management and provision of all facilities engineering modification and maintenance services for a site or platform",$row['Title']);
$unspsc[$noOilRigs] = $row['UNSPSC']; $unspsc[$noOilRigs] = $row['UNSPSC'];
} }
  $query = 'SELECT "CNID","category","value"
$query = "SELECT CNID,category,value FROM contractnotice
FROM `contractnotice` WHERE "categoryUNSPSC" IS NULL OR "categoryUNSPSC" = 0';
WHERE `categoryUNSPSC` IS NULL OR `categoryUNSPSC` = 0"; $emptycatresult = $conn->prepare($query);
$emptycatresult = mysql_query ($query);  
$missing = Array(); $missing = Array();
if ($emptycatresult){ $emptycatresult->execute();
while ($record = mysql_fetch_assoc($emptycatresult)) { foreach ($emptycatresult->fetchAll() as $record) {
   
if ($unspsc[$record['category']] == "") { if ($unspsc[$record['category']] == "") {
$missing[$record['category']]= $missing[$record['category']]+ $record['value']; $missing[$record['category']]= $missing[$record['category']]+ $record['value'];
// echo "<br>\n Category not found for: \n"; // echo "<br>\n Category not found for: \n";
// print_r($record); // print_r($record);
} else { } else {
$result = mysql_query("UPDATE contractnotice SET categoryUNSPSC = $result = $conn->exec('UPDATE contractnotice SET "categoryUNSPSC" =
'".mysql_real_escape_string($unspsc[$record['category']])."' where CNID = \''.$unspsc[$record['category']].'\' where "CNID" = '.$record['CNID'].';');
'".mysql_real_escape_string($record['CNID'])."';");  
if ($result) echo $record['CNID']. " set to ". ($unspsc[$record['category']]) . " <br>\n"; if ($result) echo $record['CNID']. " set to ". ($unspsc[$record['category']]) . " <br>\n";
else echo "error".mysql_error(); else echo "error".$conn->errorInfo();
} }
} }
} else echo "error".mysql_error();  
asort($missing,SORT_NUMERIC); asort($missing,SORT_NUMERIC);
print_r($missing); print_r($missing);
?> ?>