From: Maxious Date: Fri, 09 Mar 2012 03:50:19 +0000 Subject: Beginning of socmed import X-Git-Url: https://maxious.lambdacomplex.org/git/?p=disclosr.git&a=commitdiff&h=f2bbb45c76d5642b35c98e6c75258c72bd7b3b62 --- Beginning of socmed import Former-commit-id: d2b0f68cc699456c27ed21dffefc4e6164cf21aa --- --- a/admin/importGov2RegisterRSSFacebookTwitter.php +++ b/admin/importGov2RegisterRSSFacebookTwitter.php @@ -1,17 +1,51 @@ create_db('disclosr-agencies'); -} catch (SetteeRestClientException $e) { - setteErrorHandler($e); + +$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; } -$db = $server->get_db('disclosr-agencies'); -createAgencyDesignDoc(); -// twitter https://docs.google.com/spreadsheet/fm?id=tsJVd9EYoAjbl014y3qMgWg.03918275400592898296.8568379511161083736&hl=en&fmcmd=5&gid=0 -// RSS https://docs.google.com/spreadsheet/fm?id=tbqjwIDHKHiVYF_glJ93GgA.03918275400592898296.8789688748524615194&authkey=CJDP-uQG&hl=en_GB&fmcmd=5&gid=0 -// facebook https://docs.google.com/spreadsheet/fm?id=tkcqoo9wrgzNWmoANuVhsBw.03918275400592898296.3040387705062056060&authkey=CKzl7r0I&hl=en_GB&fmcmd=5&gid=0 +function extractCSVAccounts($url, $nameField, $accountField, $filter) { + global $accounts, $nametoid; + $request = Requests::get($url); + $Data = str_getcsv($request->body, "\n"); //parse the rows + $headers = Array(); + foreach ($Data as $num => $line) { + $Row = str_getcsv($line, ","); + if ($num == 0) { + + } else if ($num == 1) { + $headers = $Row; + //print_r($headers); + } else { + if (isset($Row[array_search($nameField, $headers)])) { + $agencyName = $Row[array_search($nameField, $headers)]; + if (!$filter || $Row[array_search("State", $headers)] == "NAT") { + if (!in_array(trim($agencyName), array_keys($nametoid))) { + echo "$agencyName missing" . PHP_EOL; + } else { + // echo $Row[array_search($nameField, $headers)] . PHP_EOL; + } + } + } else { + //echo "error finding agency" . $line . PHP_EOL; + } + } + } +} + +// http://agimo.govspace.gov.au/page/gov2register/ +// twitter +extractCSVAccounts("https://docs.google.com/spreadsheet/pub?key=0Ap1exl80wB8OdHNKVmQ5RVlvQWpibDAxNHkzcU1nV2c&single=true&gid=0&output=csv", "Agency/Body/Event", "", true); +// RSS +// https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGJxandJREhLSGlWWUZfZ2xKOTNHZ0E&output=csv +// facebook +//extractCSVAccounts("https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGtjcW9vOXdyZ3pOV21vQU51VmhzQnc&single=true&gid=0&output=csv","",""); /* * http://australia.gov.au/news-and-media/media-release-rss-feeds --- a/getAgency.php +++ b/getAgency.php @@ -14,10 +14,10 @@ echo "
    "; foreach ($value as $subkey => $subvalue) { if (isset($schemas['agency']["properties"][$key]['x-property'])) { - echo '
  1. '; - } else { - echo "
  2. "; - } + echo '
  3. '; + } else { + echo "
  4. "; + } echo "$subvalue
  5. "; } echo "
"; @@ -27,11 +27,11 @@ } else { echo ""; } - if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") { - echo "view"; - } else { - echo "$value"; - } + if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") { + echo "view"; + } else { + echo "$value"; + } } echo ""; } @@ -53,12 +53,12 @@ } else if ($key == "parentOrg") { echo ""; - } else { + } else { echo ""; if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") { echo "view"; @@ -69,7 +69,7 @@ } } } - // +// } function addDefaultFields($row) { @@ -78,13 +78,17 @@ foreach ($defaultFields as $defaultField) { if (!isset($row[$defaultField])) { if ($schemas['agency']['properties'][$defaultField]['type'] == "string") { - - $row[$defaultField] = ""; - + $row[$defaultField] = ""; } if ($schemas['agency']['properties'][$defaultField]['type'] == "array") { - $row[$defaultField] = Array(""); + } + } else if ($schemas['agency']['properties'][$defaultField]['type'] == "array") { + if (is_array($row[$defaultField])) { + $row[$defaultField][] = ""; + } else { + $value = $row[$defaultField]; + $row[$defaultField] = Array($value); } } } @@ -94,20 +98,28 @@ $db = $server->get_db('disclosr-agencies'); if (isset($_REQUEST['id'])) { - //get an agency record as json/html, search by name/abn/id +//get an agency record as json/html, search by name/abn/id // by name = startkey="Ham"&endkey="Ham\ufff0" // edit? $row = $db->get($_REQUEST['id']); - //print_r($row); +//print_r($row); if (sizeof($_POST) > 0) { - //print_r($_POST); +//print_r($_POST); foreach ($_POST as $postkey => $postvalue) { if ($postvalue == "") { unset($_POST[$postkey]); } - if (is_array($postvalue) && count($postvalue) == 1 && $postvalue[0] == "") { - unset($_POST[$postkey]); + if (is_array($postvalue)) { + if (count($postvalue) == 1 && $postvalue[0] == "") { + unset($_POST[$postkey]); + } else { + foreach ($_POST[$postkey] as $key => &$value) { + if ($value == "") { + unset($_POST[$postkey][$key]); + } + } + } } } if (isset($_POST['_id']) && $db->get_rev($_POST['_id']) == $_POST['_rev']) { @@ -124,9 +136,9 @@ if ($mode == "edit") { $row = addDefaultFields(object_to_array($row)); } else { - $row = object_to_array($row); - } - + $row = object_to_array($row); + } + if ($mode == "view") { echo '
'; echo '"; @@ -153,44 +165,44 @@ }; - $value) { - echo displayValue($key, $value, $mode); - } - if ($mode == "view") { - echo "

' . $row['name'] . "

"; - } - if ($mode == "edit") { - echo ''; - } -} else { - - try { - /* $rows = $db->get_view("app", "showNamesABNs")->rows; - //print_r($rows); - foreach ($rows as $row) { - // print_r($row); - echo '
  • ' . - (isset($row->value->name) && $row->value->name != "" ? $row->value->name : "NO NAME " . $row->value->abn) - . '
  • '; - } */ - $rows = $db->get_view("app", "byName")->rows; - //print_r($rows); -echo '"; + } catch (SetteeRestClientException $e) { + setteErrorHandler($e); + } + } + include_footer(); + ?> + --- a/schemas/agency.json.php +++ b/schemas/agency.json.php @@ -33,6 +33,8 @@ "appointmentsURL" => Array("type" => "string", "required" => true, "x-title" => "Agency Appointments/Boards", "description" => "Departmental and agency appointments and vacancies , mandated by the Senate"), "advertisingURL" => Array("type" => "string", "required" => true, "x-title" => "Approved Advertising Campaigns", "description" => " Agency advertising and public information projects, mandated by the Senate "), "hasRSS" => Array("type" => "array", "required" => true, "x-title" => "Has RSS", "description" => ""), + "hasBlog" => Array("type" => "array", "required" => true, "x-title" => "Has Blog", "description" => ""), + "hasMobileApp" => Array("type" => "array", "required" => true, "x-title" => "Has Mobile App", "description" => ""), "hasMailingList" => Array("type" => "array", "required" => true, "x-title" => "Has Mailing List", "description" => "", "items" => Array("type" => "string")), "hasTwitter" => Array("type" => "array", "required" => true, "x-title" => "Has Twitter", "description" => "",