From: Maxious Date: Sat, 14 Jan 2012 08:38:58 +0000 Subject: Data export for alaveteli X-Git-Url: https://maxious.lambdacomplex.org/git/?p=disclosr.git&a=commitdiff&h=15098a9c68ce40f96d805a3efbebe3832c67e61c --- Data export for alaveteli Former-commit-id: 94980807a4ab6705611f602879d6b7dd0e7e62f1 --- --- /dev/null +++ b/alaveteli/exportAgencies.csv.php @@ -1,1 +1,75 @@ +get_db('disclosr-agencies'); + +$tag = Array(); +try { + $rows = $db->get_view("app", "byDeptStateName", null, true)->rows; + //print_r($rows); + foreach ($rows as $row) { + $tag[$row->value] = phrase_to_tag(dept_to_portfolio($row->key)); + } +} catch (SetteeRestClientException $e) { + setteErrorHandler($e); +} + +$fp = fopen('php://output', 'w'); +if ($fp && $db) { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.' . date("c") . '.csv"'); + header('Pragma: no-cache'); + header('Expires: 0'); + fputcsv($fp, $headers); + try { + $agencies = $db->get_view("app", "byCanonicalName", null, true)->rows; + //print_r($rows); + foreach ($agencies as $agency) { + // print_r($agency); + $row = Array(); + $row["#id"] = $agency->value->_id; + $row["name"] = $agency->value->name; + if (isset($agency->value->foi_email)) { + $row["request_email"] = $agency->value->foi_email; + } else { + $row["request_email"] = "foi@".GetDomain($agency->value->website); + // + } + if (isset($agency->value->short_name)) { + $row["short_name"] = $agency->value->short_name; + } else { + $out = Array(); + preg_match_all('/[A-Z]/', $agency->value->name, $out); + $row["short_name"] = implode("",$out[0]); + } + $row["notes"] = ""; + $row["publication_scheme"] = $agency->value->infoPublicationSchemeURL; + $row["home_page"] = $agency->value->website; + if ($agency->value->orgType == "FMA-DepartmentOfState") { + $row["tag_string"] = $tag[$agency->value->_id]; + } else { + $row["tag_string"] = $tag[$agency->value->parentOrg];; + } + + fputcsv($fp, array_values($row)); + + if (isset($agency->value->foiBodies)) { + foreach ($agency->value->foiBodies as $foiBody) { + $row['name'] = $foiBody; + $row['short_name'] = ""; + fputcsv($fp, array_values($row)); + } + } + } + } catch (SetteeRestClientException $e) { + setteErrorHandler($e); + } + + die; +} +?> + --- /dev/null +++ b/alaveteli/exportCategories.rb.php @@ -1,1 +1,23 @@ +get_db('disclosr-agencies'); +try { + $rows = $db->get_view("app", "byDeptStateName", null, true)->rows; + //print_r($rows); + foreach ($rows as $row) { + echo ' [ "'.phrase_to_tag(dept_to_portfolio($row->key)).'","'. dept_to_portfolio($row->key).'","'.dept_to_portfolio($row->key).'" ],'.PHP_EOL; + } +} catch (SetteeRestClientException $e) { + setteErrorHandler($e); +} +echo '])'; +?> + --- a/graph.php +++ b/graph.php @@ -15,7 +15,7 @@ $rows = $db->get_view("app", "byCanonicalName", null, true)->rows; //print_r($rows); foreach ($rows as $row) { - echo "nodes[\"{$row->value}\"] = graph.newNode({label: \"{$row->key}\"});" . PHP_EOL; + echo "nodes[\"{$row->value->_id}\"] = graph.newNode({label: \"{$row->key}\"});" . PHP_EOL; } } catch (SetteeRestClientException $e) { setteErrorHandler($e); --- a/include/common.inc.php +++ b/include/common.inc.php @@ -1,4 +1,15 @@ stdClass return (object) $array; } + +function dept_to_portfolio($deptName) { + return trim(str_replace("Department of", "", str_replace("Department of the", "Department of", $deptName))); +} +function phrase_to_tag ($phrase) { + return str_replace(" ","_",str_replace(",","",strtolower($phrase))); +} +function GetDomain($url) +{ +$nowww = ereg_replace('www\.','',$url); +$domain = parse_url($nowww); +if(!empty($domain["host"])) + { + return $domain["host"]; + } else + { + return $domain["path"]; + } +} + ?> --- a/include/couchdb.inc.php +++ b/include/couchdb.inc.php @@ -1,6 +1,8 @@ save($obj, true); } -require ('couchdb/settee/src/settee.php'); if( php_uname('n') == "vanille") { $server = new SetteeServer('http://192.168.178.21:5984'); } else - if( php_uname('n') == "kyuubey") { + if( php_uname('n') == "KYUUBEY") { -$server = new SetteeServer('http://192.168.1.8:5984'); +$server = new SetteeServer('http://192.168.1.148:5984'); } else { $server = new SetteeServer('http://127.0.0.1:5984'); } function setteErrorHandler($e) { echo $e->getMessage() . "
" . PHP_EOL; } - ?> --- a/schemas/agency.json.php +++ b/schemas/agency.json.php @@ -5,7 +5,10 @@ "type" => "object", "properties" => Array( "name" => Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), + "short_name" => Array("type" => "string", "required" => false, "x-title"=> "Agency Short Name", "description" => "Agency Name shortened, usually to an acronym"), "otherNames" => Array("type" => "array", "required" => true, "x-title" => "Agency Past/Other Names", "description" => "Agency Names", + "items" => Array("type" => "string")), + "foiBodies" => Array("type" => "array", "required" => true, "x-title" => "FOI Bodies", "description" => "Organisational units within this agency that are subject to FOI Act but are not autonomous", "items" => Array("type" => "string")), "orgType"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"), "parentOrg"=> Array("type" => "string", "required" => true, "x-title"=> "Agency Name", "description" => "Agency Name, most recent and broadest"),