public static function loadDocsJSON($client) { // Load json files $dir = __DIR__ . DIRECTORY_SEPARATOR . 'docs' . DIRECTORY_SEPARATOR . 'nv'; $count = 0; if ($handle = opendir($dir)) { parent::$logger->debug("Writing files from directory: " . $dir); $doc = new MLPHP\Document($client); while (false !== ($file = readdir($handle))) { if (substr($file, 0, 1) !== ".") { $doc->setContentType("application/json"); $content = $doc->setContentFile($dir . '/' . $file)->getContent(); $uri = '/legislators/' . $file; // URI example: '/legislators/Care.json' $obj = json_decode($content); $params = array("collection" => $obj->{'old_roles'}->{'2009-2010'}[0]->party); $count++; parent::$logger->debug($count . ': ' . $uri); // Write content to database via REST client $doc->write($uri, $params); } } closedir($handle); } parent::$logger->debug('JSON files loaded: ' . $count); }
echo "<script>\$(window).load(function () { document.write('" . $items . " loaded') });</script>"; } $restClient = new MLPHP\RESTClient($mlphp['host'], $mlphp['port'], $mlphp['path'], $mlphp['version'], $mlphp['username'], $mlphp['password'], $mlphp['auth']); $rootdir = 'bills'; $subdirs = array('110', '111', '112'); // directories to import from // Loop through files from subdirectories foreach ($subdirs as $subdir) { $count = 0; $dir = $rootdir . '/' . $subdir; if ($handle = opendir($dir)) { //echo "Writing files from directory: " . $dir . "<br />"; $doc = new MLPHP\Document($restClient); while (false !== ($file = readdir($handle))) { if (substr($file, 0, 1) !== ".") { $doc->setContentType("application/xml"); $content = $doc->setContentFile($dir . '/' . $file)->getContent(); $uri = '/bills/' . $subdir . '/' . $file; // URI example: '/bills/112/h321.xml' $dom = new DOMDocument(); $dom->loadXML($content); // Only write bills with related bills and short titles $num_rel_bills = $dom->getElementsByTagName('relatedbill')->length; $len_title = strlen($dom->getElementsByTagName('title')->item(0)->nodeValue); if ($num_rel_bills == 0 || $len_title > 80) { continue; } $xpath = new DOMXPath($dom); // Set collection base on bill type. Example: 'hr' (House resolution) $type = $xpath->query('//bill/@type')->item(0)->nodeValue; $params = array("collection" => $type);
// Get directory relative to current directory $doc6 = new MLPHP\Document($client); // Create a Document object (passing the REST client) if ($handle = opendir($dir)) { // Create a directory handle for reading echo 'Reading files from directory: ' . $dir . "\n\n"; $files = array(); while (false !== ($file = readdir($handle))) { // Read each file in the directory if (substr($file, 0, 1) !== '.') { // Ignore special files $files[] = $file; // Store the file URIs in an array $doc6->setContentFile($dir . '/' . $file); // Set the file as the document content $doc6->setContentType('application/xml'); // Set the content type for the document $uri6 = '/' . $file; // Define the URI for the document $doc6->write($uri6); // Write the document to the database } } closedir($handle); } // Read the documents from the database echo "Read the documents:\n"; foreach ($files as $i => $file) { // Loop through the file URIs echo 'File #' . ($i + 1) . ': '; $uri6 = '/' . $file;