Esempio n. 1
0
#!/usr/bin/php
<?php 
include "../api/Init.php";
include "../api/DataImporter.php";
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("./historical_data"));
$Regex = new RegexIterator($objects, '/^.+\\.txt$/i', RecursiveRegexIterator::GET_MATCH);
foreach ($Regex as $name => $object) {
    echo "Importing file: " . $name . "\n";
    $DI = new DataImporter($db, file_get_contents($name));
    // most of the supplied files have the address as part of the filename
    $str = explode("/", $name);
    if (count($str) == 4) {
        $query = "insert into meter_info(`meter_id`, `address`) values(:meter_id, :address);";
        $stmt = $db->prepare($query);
        $id = $DI->get_meter_id();
        $stmt->bindParam(':meter_id', $id);
        $stmt->bindParam(':address', $str[2]);
        $stmt->execute();
    } else {
        $query = "insert into meter_info(`meter_id`, `address`) values(:meter_id, 'unknown');";
        $stmt = $db->prepare($query);
        $id = $DI->get_meter_id();
        $stmt->bindParam(':meter_id', $id);
        $stmt->execute();
    }
}
Esempio n. 2
0
<?php

require_once '../config.php';
require_once 'DataImporter.php';
$db = pg_connect($connection_string) or die('Unable to connect to database server - check config.php!');
$importer = new DataImporter();
$importer->db = $db;
date_default_timezone_set('Europe/Ljubljana');
// Should be set in php config
// Cleanup
$importer->cleanup();
// Import part of speeches
$importer->importPartOfSpeech();
// Import data files (parameter 0 is script name)
if (count($argv) == 1) {
    die('Please pass data directory as (only) parameter!');
}
$dirPath = $argv[1];
$directory = new DirectoryIterator($dirPath);
foreach ($directory as $file) {
    if ($file->isFile() && $file->getExtension() == 'xml') {
        $path = $file->getPathname();
        echo date('d.m.Y H:i:s') . " Importing file {$path}...\n";
        $importer->importFile($path);
    }
}
pg_close($db);