-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.php
68 lines (51 loc) · 1.86 KB
/
api.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
<?php
header('Content-type: text/json');
$content = iconv('windows-1254', 'utf-8', file_get_contents("http://www.koeri.boun.edu.tr/scripts/lst0.asp"));
preg_match_all("/<pre>(.*?)<\/pre>/s", $content, $pre);
$rows = explode("\n", str_replace(["<pre>", "</pre>"], "", $pre[0][0]));
for ($i = 0; $i < 7; $i++) array_shift($rows);
$rows = array_filter(array_map(function ($row) {
$parts = explode(' ', $row);
$parts = array_filter($parts, function ($row) {
return strlen($row) > 1;
});
$parts = array_map(function ($part) {
if ($part === '-.-') return null;
return strip_tags(
htmlspecialchars(
str_replace(
["\t", "\s", "\w", "\r", "\n"],
'',
trim($part)
)
)
);
}, $parts);
return array_values($parts);
}, $rows), function ($row) {
return count($row) > 2;
});
$arr = [];
foreach ($rows as $row) {
$arr[] = [
'fingerpass' => md5($row[0] . sprintf("%s,%s", $row[1], $row[2]) . $row[5] . $row[7]),
'time' => array(
'date' => explode(' ', $row[0])[0],
'time' => explode(' ', $row[0])[1],
),
'geolocation' => sprintf("%s,%s", $row[1], $row[2]),
'depth' => $row[3],
'ml' => $row[5],
'location' => array(
'full' => $row[7],
'city' => str_replace(array('(', ')'), '', explode('(', $row[7])[1]),
'state' => count(explode('-', explode('(', $row[7])[0])) > 1 ? explode('-', explode('(', $row[7])[0])[1] : explode('(', $row[7])[0],
'district' => count(explode('-', explode('(', $row[7])[0])) > 1 ? explode('-', explode('(', $row[7])[0])[0] : null,
),
'precision' => $row[8]
];
}
echo json_encode(array(
'source' => 'http://www.koeri.boun.edu.tr',
'data' => $arr
));