<?php |
<?php |
|
|
include_once("../include/common.inc.php"); |
require_once '../include/common.inc.php'; |
require($basePath . 'lib/phpquery/phpQuery/phpQuery.php'); |
|
|
|
setlocale(LC_CTYPE, 'C'); |
$db = $server->get_db('disclosr-agencies'); |
|
$rows = $db->get_view("app", "byName")->rows; |
|
$nametoid = Array(); |
|
$accounts = Array(); |
|
foreach ($rows as $row) { |
|
$nametoid[trim($row->key)] = $row->value; |
|
} |
|
$nameField = "Agency"; |
|
$elevenField = "2011-2012"; |
|
$twelveField = "2012-2013"; |
|
// $request = Requests::get($url); |
|
//echo $url; |
|
// $Data = str_getcsv($request->body, "\n"); //parse the rows |
|
$Data = str_getcsv(file_get_contents("ausbudget.csv"), "\n"); //parse the rows |
|
$headers = Array(); |
|
foreach ($Data as $num => $line) { |
|
$Row = str_getcsv($line, ","); |
|
if ($num == 0) { |
|
$headers = $Row; |
|
print_r($headers); |
|
} else { |
|
if (isset($Row[array_search($nameField, $headers)])) { |
|
$agencyName = $Row[array_search($nameField, $headers)]; |
|
if (!in_array(trim($agencyName), array_keys($nametoid))) { |
|
echo trim($agencyName) . " missing" . PHP_EOL; |
|
} else { |
|
//echo $Row[array_search($nameField, $headers)] . PHP_EOL; |
|
// print_r($Row); |
|
if (!is_array($accounts[$nametoid[trim($agencyName)]]["budget"]['2011-2012'])) $accounts[$nametoid[trim($agencyName)]]["budget"]['2011-2012'] = Array(); |
|
if (!is_array($accounts[$nametoid[trim($agencyName)]]["budget"]['2012-2013'])) $accounts[$nametoid[trim($agencyName)]]["budget"]['2012-2013'] = Array(); |
|
|
function getTextFromNode($Node, $Text = "") { |
if (!isset($accounts[$nametoid[trim($agencyName)]]["budget"]['2011-2012']['value'])) $accounts[$nametoid[trim($agencyName)]]["budget"]['2011-2012']['value'] = 0; |
if (!isset($Node->tagName) || $Node->tagName == null) { |
if (!isset($accounts[$nametoid[trim($agencyName)]]["budget"]['2012-2013']['value'])) $accounts[$nametoid[trim($agencyName)]]["budget"]['2012-2013']['value'] = 0; |
return $Text . $Node->textContent; |
$accounts[$nametoid[trim($agencyName)]]["budget"]['2011-2012']['value'] += $Row[array_search($elevenField, $headers)]; |
|
$accounts[$nametoid[trim($agencyName)]]["budget"]['2012-2013']['value'] += $Row[array_search($twelveField, $headers)]; |
|
|
|
$accounts[$nametoid[trim($agencyName)]]["budget"]['2011-2012']['source'] = 'http://budgetaus.net/'; |
|
$accounts[$nametoid[trim($agencyName)]]["budget"]['2012-2013']['source'] = 'http://budgetaus.net/'; |
|
} |
|
} else { |
|
echo "error finding any agency" . $line . PHP_EOL; |
|
} |
} |
} |
$Node = $Node->firstChild; |
|
if (isset($Node) && $Node != null) { |
|
$Text = getTextFromNode($Node, $Text); |
|
} |
|
while (isset($Node->nextSibling) && $Node->nextSibling != null) { |
|
$Text = getTextFromNode($Node->nextSibling, $Text); |
|
$Node = $Node->nextSibling; |
|
} |
|
return $Text; |
|
} |
} |
|
|
$dir = "./ausbudget/"; |
|
$dhandle = opendir("./ausbudget/"); |
|
// define an array to hold the files |
//print_r($accounts); |
$files = array(); |
foreach ($accounts as $id => $allvalues) { |
if ($dhandle) { |
echo $id . "<br>" . PHP_EOL; |
// loop through all of the files |
$doc = object_to_array($db->get($id)); |
while (false !== ($fname = readdir($dhandle))) { |
// print_r($doc); |
if (($fname != '.') && ($fname != '..')) { |
|
echo "$fname <br>"; |
foreach ($allvalues as $valueType => $values) { |
$html = phpQuery::newDocumentHTML(file_get_contents($dir . $fname)); |
if (!isset($doc['statistics'][$valueType]) || !is_array($doc['statistics'][$valueType])) { |
phpQuery::selectDocument($html); |
|
foreach (pq('table')->elements as $table) { |
$doc['statistics'][$valueType] = Array(); |
echo "loltable"; |
|
//echo $table->ownerDocument->saveXML($table); |
|
foreach (pq('tr')->elements as $row) { |
|
echo "lolrow"; |
|
$rowText = getTextFromNode($row); |
|
if (strpos($rowText,"Twitter") === false) { |
|
echo "<b>".pq("td:first",$row)->text()."</b><br>"; |
|
echo pq("td",$row)->text() . "<br>"; |
|
} |
|
} |
|
} |
|
} |
} |
break; |
$doc['statistics'][$valueType] = array_unique(array_merge($doc['statistics'][$valueType], $values)); |
} |
} |
|
|
|
$db->save($doc); |
} |
} |
?> |
?> |
|
|