-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaces.php
151 lines (108 loc) · 3.12 KB
/
places.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
main();
//FileParser("");
//GetFiles("");
//FileImport("");
function main()
{
$dataDirs = array();
array_push($dataDirs, './dictionaries');
//var_dump($dataDirs);
$fileList = GetFiles($dataDirs);
//print_r($fileList);
$fileContents = GetFlattenedMDArray($fileList);
CreateFileOutput($fileContents);
}
function CreateFileOutput($fileContents)
{
$fileLength = (count($fileContents)-1);
$fileOutput = "";
$cities = GetFlattenedMDArray(array('locations/cities'));
$states = GetFlattenedMDArray(array('locations/states'));
$streetEndings = GetFlattenedMDArray(array('locations/streetEndings'));
$cityLength = (count($cities)-1);
$statesLength = (count($states)-1);
$endingsLength = (count($streetEndings)-1);
for($i = 0; $i<10000; $i++){
$fileOutput = $fileOutput . "insert into places(address_line_one, address_line_two, notes) VALUES" . " ('" . rand(0,3000) . " " . $fileContents[rand(0,$fileLength)] . " " . $streetEndings[rand(0,$endingsLength)] . "', '" . $cities[rand(0,$cityLength)] . ", " . $states[rand(0,$statesLength)] . ", " . rand(10000,99999) . "', '');" . "\n";
}
//echo $fileOutput;
file_put_contents("outputScripts/PlaceInserts_".gmdate("Y-m-d H:i:s") . ".txt", $fileOutput);
echo "File write done \n";
if($outputtingNames){
for($j=0;$j<$fileLength;$j++){
file_put_contents("outputScripts/names.txt", $fileContents[$j]."\n", FILE_APPEND);
}
}
}
function GetFlattenedMDArray($fileList)
{
$fileContents = array();
foreach($fileList as &$aryElem)
{
$singleFileContents = FileImport($aryElem);
foreach ($singleFileContents as &$fileAryElem) {
array_push($fileContents, $fileAryElem);
}
unset($fileAryElem);
}
unset($aryElem);
return $fileContents;
}
function FileParser($file)
{
$firstPass = explode("\n", $file);
$secondPass = array();
foreach($firstPass as &$fp)
{
/*
if (strpos($fp, 'ABRANCHES 19') !== false) {
echo 'ABRANCHES 19'."\n";
}
*/
$explode = explode("\t", $fp);
$passBack = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $explode[0]);
array_push($secondPass, str_replace("'", "", ucfirst(strtolower($passBack))));
/*
if (strpos($fp, 'ABRANCHES 19') !== false) {
echo $passBack."\n";
}
*/
}
unset($fp);
// print_r($secondPass);
return $secondPass;
PrintCurrentFunction(__FUNCTION__);
}
//Get the data from the files on the list
function FileImport($filePathAndName)
{
$myfile = fopen($filePathAndName, "r") or die("Unable to open file!");
$newFile = fread($myfile,filesize($filePathAndName));
fclose($myfile);
//print_r($myfile);
$fileAry = FileParser($newFile);
return $fileAry;
PrintCurrentFunction(__FUNCTION__);
}
//Get the full file path of the files in the data directories.
function GetFiles($ArrayOfDataDirectories)
{
$outputFileList = array();
$fileList = scandir($ArrayOfDataDirectories[0]);
foreach($fileList as &$files)
{
if($files != "." && $files != "..")
{
array_push($outputFileList, $ArrayOfDataDirectories[0] . "/" . $files);
}
}
unset($files);
//PrintCurrentFunction(__FUNCTION__);
return $outputFileList;
}
function PrintCurrentFunction($funcName)
{
echo $funcName . " working \n";
}
?>