Add sag as a git submodule
[disclosr.git] / import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require_once 'sag/src/Sag.php';
$sag = new Sag();
$sag->setDatabase("disclosr-agencies", true);
$file = "agencies.csv";
$handle = fopen($file, "r");
$fieldNames = Array();
$line = 0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        if ($line == 0) {
                $fieldNames = $data;
        }
        else {
                $agency = Array();
                $valueCount = 0;
                foreach ($data as $value) {
                        if ($value != "") $agency[$fieldNames[$valueCount]] = $value;
                        $valueCount++;
                }
                $agency["lastScraped"] = "1/1/1970";
                $agency["scrapeDepth"] = 1;
                var_dump($agency);
                $sag->post($agency);
        }
        $line++;
        if ($line % 10000 == 0) echo "$line records... \n";
}
fclose($handle);
echo "Found a total of $line records in $file.\n";
?>