-
Notifications
You must be signed in to change notification settings - Fork 6
/
log_combine.php
62 lines (52 loc) · 1.52 KB
/
log_combine.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
<?php
/**
* @author Ebo Eppenga
* @copyright 2022
*
* GoldStar Buy and Sell bot based on signals from for example TradeView
* or any other platform using PHP Binance API from JaggedSoft.
*
* log_combine.php?files=history|trades|errors|profits
* Combines all the data/*_log_history|trades|errors.csv files
* If left empty defaults to *_log_history.csv files
*
*/
// Set variables
$combined = "";
$data = "data/";
// Combine history or trades
if (isset($_GET["files"])) {
if ($_GET["files"] == "history") {
$logfiles = "log_history.csv";
} elseif ($_GET["files"] == "trades") {
$logfiles = "log_trades.csv";
} elseif ($_GET["files"] == "errors") {
$logfiles = "log_errors.csv";
} elseif ($_GET["files"] == "profits") {
$logfiles = "log_profits.csv";
} else {
echo "Error: Undefined what combined log to create!";
exit();
}
} else {
$logfiles = "log_history.csv";
}
// First check if data folder exists
if (!file_exists($data)) {echo "Error: No data folder!"; exit();}
// Get file list
$files = scandir($data);
// Filter all *_log_history|trades|errors.csv files
foreach ($files as &$file) {
if (strpos($file, "_" . $logfiles) !== false) {
$csvfiles[] = $file;
}
}
// Throw an error if no CSV files are found
if (empty($csvfiles)) {echo "Error: No CSV files found!"; exit();}
// Output *_log_history.csv files to stdout and file
foreach ($csvfiles as &$csvfile) {
$combined .= file_get_contents($data . $csvfile);
}
file_put_contents($data . $logfiles, $combined);
echo $combined;
?>