Testing facebook imports
Testing facebook imports


Former-commit-id: 26f7cc47bbd4c30bb9dab99a095d0363e52c3766

[submodule "couchdb/couchdb-lucene"] [submodule "couchdb/couchdb-lucene"]
path = couchdb/couchdb-lucene path = couchdb/couchdb-lucene
url = https://github.com/rnewson/couchdb-lucene.git url = https://github.com/rnewson/couchdb-lucene.git
[submodule "couchdb/settee"] [submodule "couchdb/settee"]
path = couchdb/settee path = couchdb/settee
url = https://github.com/inadarei/settee.git url = https://github.com/inadarei/settee.git
[submodule "lib/springy"] [submodule "lib/springy"]
path = lib/springy path = lib/springy
url = https://github.com/dhotson/springy.git url = https://github.com/dhotson/springy.git
[submodule "lib/php-diff"] [submodule "lib/php-diff"]
path = lib/php-diff path = lib/php-diff
url = https://github.com/chrisboulton/php-diff.git url = https://github.com/chrisboulton/php-diff.git
[submodule "lib/Requests"] [submodule "lib/Requests"]
path = lib/Requests path = lib/Requests
url = https://github.com/rmccue/Requests.git url = https://github.com/rmccue/Requests.git
[submodule "javascripts/flotr2"] [submodule "javascripts/flotr2"]
path = javascripts/flotr2 path = javascripts/flotr2
url = https://github.com/HumbleSoftware/Flotr2.git url = https://github.com/HumbleSoftware/Flotr2.git
  [submodule "lib/phpquery"]
  path = lib/phpquery
  url = https://github.com/TobiaszCudnik/phpquery.git
   
  <?php
 
  require_once '../include/common.inc.php';
 
  $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;
  }
 
  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","Agency","Name");
 
  /*
  * http://australia.gov.au/news-and-media/media-release-rss-feeds
  * http://australia.gov.au/news-and-media/social-media/blogs
  * http://australia.gov.au/news-and-media/social-media/twitter
  * http://australia.gov.au/news-and-media/social-media/facebook
  * http://australia.gov.au/news-and-media/social-media/youtube
  * http://australia.gov.au/news-and-media/social-media/flickr
  * http://australia.gov.au/news-and-media/social-media/apps http://www.harmony.gov.au/get-involved/app-downloads.htm http://www.em.gov.au/Resources/Pages/Before-the-Storm-phone-game.aspx
  * http://australia.gov.au/news-and-media/social-media/podcasts
  */
  ?>
 
<?php <?php
   
require_once '../include/common.inc.php'; require_once '../include/common.inc.php';
  require($basePath.'lib/phpquery/phpQuery/phpQuery.php');
   
$db = $server->get_db('disclosr-agencies'); $db = $server->get_db('disclosr-agencies');
$rows = $db->get_view("app", "byName")->rows; $rows = $db->get_view("app", "byName")->rows;
$nametoid = Array(); $nametoid = Array();
$accounts = Array(); $accounts = Array();
foreach ($rows as $row) { foreach ($rows as $row) {
$nametoid[trim($row->key)] = $row->value; $nametoid[trim($row->key)] = $row->value;
} }
  function extractHTMLAccounts($url, $accountType) {
  global $accounts, $nametoid;
  $request = Requests::get($url);
  $doc = phpQuery::newDocumentHTML($request->body);
  phpQuery::selectDocument($doc);
  foreach (pq('tr')->elements as $tr) {
  //echo $tr->nodeValue.PHP_EOL;
  $agency = "";
  $url = "";
  foreach ($tr->childNodes as $td) {
  $class = $td->getAttribute("class");
  //echo "cccc $class ".$td->nodeValue.PHP_EOL;
  if ($class == "s11" || $class == "s10" || $class == "s7") {
  $agency = $td->nodeValue;
  } else if ($class == "s6" || $class == "s9"){
  $url = $td->nodeValue;
  foreach($td->childNodes as $a) {
  $href = $a->getAttribute("href");
  if ($href != "") {
  $url = $href;
  }
  }
  }
  }
  if ($agency != "" && $url != "") {
  if (!in_array(trim($agency), array_keys($nametoid))) {
  echo trim($agency)." missing" . PHP_EOL;
  } else {
  // echo $agency." = ".$url.PHP_EOL;
  $accounts[$nametoid[trim($agency)]][$accountType][] = $url;
  }
   
  }
  }
   
  }
   
function extractCSVAccounts($url, $nameField, $accountField, $filter) { function extractCSVAccounts($url, $accountType, $nameField, $accountField, $filter) {
global $accounts, $nametoid; global $accounts, $nametoid;
$request = Requests::get($url); $request = Requests::get($url);
$Data = str_getcsv($request->body, "\n"); //parse the rows $Data = str_getcsv($request->body, "\n"); //parse the rows
$headers = Array(); $headers = Array();
foreach ($Data as $num => $line) { foreach ($Data as $num => $line) {
$Row = str_getcsv($line, ","); $Row = str_getcsv($line, ",",'"');
if ($num == 0) { if ($num == 0) {
} else if ($num == 1) { } else if ($num == 1) {
$headers = $Row; $headers = $Row;
//print_r($headers); //print_r($headers);
} else { } else {
if (isset($Row[array_search($nameField, $headers)])) { if (isset($Row[array_search($nameField, $headers)])) {
$agencyName = $Row[array_search($nameField, $headers)]; $agencyName = $Row[array_search($nameField, $headers)];
if (!$filter || $Row[array_search("State", $headers)] == "NAT") { if (!$filter || $Row[array_search("State", $headers)] == "NAT") {
if (!in_array(trim($agencyName), array_keys($nametoid))) { if (!in_array(trim($agencyName), array_keys($nametoid))) {
echo "$agencyName missing" . PHP_EOL; echo trim($agencyName)." missing" . PHP_EOL;
} else { } else {
// echo $Row[array_search($nameField, $headers)] . PHP_EOL; // echo $Row[array_search($nameField, $headers)] . PHP_EOL;
  $accounts[$nametoid[trim($agencyName)]][$accountType][] = $Row[array_search($accountField, $headers)];
} }
} }
} else { } else {
//echo "error finding agency" . $line . PHP_EOL; //echo "error finding agency" . $line . PHP_EOL;
} }
} }
} }
} }
   
// http://agimo.govspace.gov.au/page/gov2register/ // http://agimo.govspace.gov.au/page/gov2register/
// twitter // twitter
extractCSVAccounts("https://docs.google.com/spreadsheet/pub?key=0Ap1exl80wB8OdHNKVmQ5RVlvQWpibDAxNHkzcU1nV2c&single=true&gid=0&output=csv", "Agency/Body/Event", "", true); extractCSVAccounts("https://docs.google.com/spreadsheet/pub?key=0Ap1exl80wB8OdHNKVmQ5RVlvQWpibDAxNHkzcU1nV2c&single=true&gid=0&output=csv", "Twitter", "Agency/Body/Event", "", true);
// RSS // RSS
// https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGJxandJREhLSGlWWUZfZ2xKOTNHZ0E&output=csv extractHTMLAccounts("https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGJxandJREhLSGlWWUZfZ2xKOTNHZ0E&output=html", "RSS");
// facebook // facebook
//extractCSVAccounts("https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGtjcW9vOXdyZ3pOV21vQU51VmhzQnc&single=true&gid=0&output=csv","",""); extractHTMLAccounts("https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGtjcW9vOXdyZ3pOV21vQU51VmhzQnc&single=true&gid=0&output=html", "Facebook");
   
/*  
* http://australia.gov.au/news-and-media/media-release-rss-feeds  
* http://australia.gov.au/news-and-media/social-media/blogs  
* http://australia.gov.au/news-and-media/social-media/twitter  
* http://australia.gov.au/news-and-media/social-media/facebook  
* http://australia.gov.au/news-and-media/social-media/youtube  
* http://australia.gov.au/news-and-media/social-media/flickr  
* http://australia.gov.au/news-and-media/social-media/apps http://www.harmony.gov.au/get-involved/app-downloads.htm http://www.em.gov.au/Resources/Pages/Before-the-Storm-phone-game.aspx  
* http://australia.gov.au/news-and-media/social-media/podcasts  
*/  
?> ?>
   
directory:b/lib/phpquery (new)