This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tickdetect.php
71 lines (62 loc) · 2.09 KB
/
tickdetect.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
// include config variables
include('config.inc.php');
$logfile = $loglocation.$logtickdetect;
// connect to db
include($securedbcreds);
$con = mysqli_connect($servername,$username,$password,$database) or die("SQL connection error");
$data = json_decode(file_get_contents('https://elitebgs.app/api/ebgs/v4/ticks'), true);
if (!$data) {
echo "Couldnt get data from elitebgs tick api";
if ($apilogtickdetect) {
$current .= "Couldnt get data from elitebgs tick api\n";
file_put_contents($logfile, $current);
}
exit();
}
$ticktimestamp = strtotime($data[0]['time']);
$tickdatetimeobj = date_create_from_format('U', $ticktimestamp);
$newtick = date_format($tickdatetimeobj, 'Y-m-d H:i:s');
//check last tick data
$lasttickquery = "SELECT * FROM dailyticks ORDER BY id DESC LIMIT 1";
if ($lasttickresult = mysqli_query($con, $lasttickquery)){
if (mysqli_num_rows($lasttickresult) > 0) {
$row = mysqli_fetch_array($lasttickresult, MYSQLI_ASSOC);
$current .= "Found latest recorded tick in db:\n";
$current .= " Known Tick: ".$row['timestamp']."\n";
$current .= " Latest Tick: ".$newtick."\n";
if ($row['timestamp'] == $newtick) {
$oldsameasnew = true;
} else {
$oldsameasnew = false;
}
}
if (mysqli_num_rows($lasttickresult) < 1) {
$oldsameasnew = false;
}
if (!$oldsameasnew) {
$current .= "New tick detected, adding to database...<br />\n";
$inserttickdata = "INSERT INTO dailyticks (timestamp) VALUES ('$newtick')";
if (!mysqli_query($con, $inserttickdata)) {
if ($apilogtickdetect) {
$current .= "SQL error, couldnt add tick to database.\n";
file_put_contents($logfile, $current);
}
exit();
} else {
if ($apilogtickdetect) {
$current .= "Tick added to database, all done.\n";
file_put_contents($logfile, $current);
}
include('tickprocessor.php');
}
} else {
if ($apilogtickdetect) {
$current .= "No new tick detected, exiting...\n";
file_put_contents($logfile, $current);
}
echo "No new tick detected, exiting...<br />\n";
exit();
}
}
?>