forked from burakodabas/deprem-api-turkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-data.php
83 lines (63 loc) · 2.63 KB
/
create-data.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
<?php
header('Content-Type: text/html; charset=utf-8');
require 'simple_html_dom.php';
$html = file_get_html('http://www.koeri.boun.edu.tr/scripts/lst6.asp');
$depremData = $html->find('pre', 0);
$depremData = $depremData->plaintext;
$kullanData = substr($depremData, '610', strlen($depremData)); // clear top junk
$currentYear = date('Y');
$depremArray = explode($currentYear, $kullanData); // read per line
$tumDepremler = array(); // create empty Array
foreach ($depremArray as $deprem) {
$deprem = $currentYear . $deprem; // explode function clear year.. and repeat fill must.
if (strlen($deprem) > 25) {
// strlen control because REVIZE (2019...) include year. and no line but include date...
$ilksel_index = strpos(substr($deprem, 71, strlen($deprem)), "İlksel");
$revize_index = strpos(substr($deprem, 71, strlen($deprem)), "REVIZE");
$yer_ismi = "";
$tip = "";
if ($revize_index) {
$yer_ismi = substr($deprem, 70, $revize_index);
$tip = substr($deprem, (71 + $revize_index), strlen($deprem));
} else if ($ilksel_index) {
$yer_ismi = substr($deprem, 71, $ilksel_index);
$tip = substr($deprem, (71 + $ilksel_index), strlen($deprem));
}
//clear $yer_ismi & $tip from space
$yer_ismi = rtrim($yer_ismi);
$tip = str_replace('(', '', $tip);
$tip = trim($tip);
$deprem = str_replace('\0', '', $deprem);
$deprem = str_replace(' ', '', $deprem);
$tarih = substr($deprem, 0, 10);
$saat = substr($deprem, 10, 8);
$enlem = substr($deprem, 18, 7);
$boylam = substr($deprem, 25, 7);
if (strpos(substr($deprem, 32, 4), '-')) {
$derinlik = substr($deprem, 32, 3);
$siddet = substr($deprem, 38, 3);
} else if (strpos(substr($deprem, 32, 5), '-')) {
$derinlik = substr($deprem, 32, 4);
$siddet = substr($deprem, 39, 3);
} else if (strpos(substr($deprem, 32, 6), '-')) {
$derinlik = substr($deprem, 32, 5);
$siddet = substr($deprem, 40, 3);
} else {
$derinlik = "bilinmiyor";
$siddet = "bilinmiyor";
}
$depremSingle = array(
'tarih' => $tarih,
'saat' => $saat,
'enlem' => $enlem,
'boylam' => $boylam,
'derinlik' => $derinlik,
'siddet' => $siddet,
'yer' => $yer_ismi,
'tip' => $tip
);
$depremToken = md5($tarih . $saat . $enlem);
array_push($tumDepremler, $depremSingle);
}
}
echo json_encode($tumDepremler, true);