-
Notifications
You must be signed in to change notification settings - Fork 0
/
moons.php
119 lines (91 loc) · 2.65 KB
/
moons.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
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type,Authorization,X-User-Agent");
header("Access-Control-Allow-Credentials: true");
header("Access-Control: public");
header("access-control-allow-methods: GET,OPTIONS");
header("Content-Type: application/json");
error_reporting(0);
$url = "https://eveskunk.com/pos.php?sessid=bd039cc011b83383a53661584b1a3d55cab61ebf47a04d1ba8d6535f92c8f8b1&solarSystemID=30001577";
$html = file_get_contents($url);
//$dom = DOMDocument::loadHTML($html);
//print_r($dom);
//$data = $dom->getElementByID("");
$data = [];
preg_match_all("#<nobr>(.*?)</nobr>#", $html, $data);
$data = $data[1];
$finals = ["Fernite Carbide", "Crystalline Carbonide", "Tungsten Carbide", "Titanium Carbide"];
$gases = ["Evaporite Deposits", "Silicates", "Atmospheric Gases", "Hydrocarbons"];
$minFuel = PHP_INT_MAX;
$maxFuel = 0;
$averageFuel = 0;
$fuelNum = 0;
$minFinal = PHP_INT_MAX;
$maxFinal = 0;
$averageFinal = 0;
$finalNum = 0;
$minGas = PHP_INT_MAX;
$maxGas = 0;
$averageGas = 0;
$gasNum = 0;
foreach($data as $string){
if(containsAny($string, $finals)){
$match = [];
preg_match("#<b>(.*?)</b>#", $string, $match);
$match = $match[1];
$match = substr($match, 0, strlen($match)-1);
$amount = intval($match);
if($amount < $minFinal){
$minFinal = $amount;
}
if($amount > $maxFinal){
$maxFinal = $amount;
}
$averageFinal += $amount;
$finalNum++;
} else if(containsAny($string, $gases)){
$match = [];
preg_match("#<b>(.*?)</b>#", $string, $match);
$match = $match[1];
$match = substr($match, 0, strlen($match)-1);
$amount = intval($match);
if($amount < $minGas){
$minGas = $amount;
}
if($amount > $maxGas){
$maxGas = $amount;
}
$averageGas += $amount;
$gasNum++;
} else if(stripos($string, "Fuel Blocks") !== false){
$match = [];
preg_match("#<b>(.*?)</b>#", $string, $match);
$match = $match[1];
$match = substr($match, 0, strlen($match)-1);
$amount = intval($match);
if($amount < $minFuel){
$minFuel = $amount;
}
if($amount > $maxFuel){
$maxFuel = $amount;
}
$averageFuel += $amount;
$fuelNum++;
}
}
$averageFinal = $averageFinal / $finalNum;
$averageGas = $averageGas / $gasNum;
$averageFuel = $averageFuel / $fuelNum;
echo json_encode(
[
"fuel"=>["min"=>$minFuel, "max"=>$maxFuel, "average"=>$averageFuel],
"final"=>["min"=>$minFinal, "max"=>$maxFinal, "average"=>$averageFuel],
"gas"=>["min"=>$minGas, "max"=>$maxGas, "average"=>$averageGas]]);
function containsAny($str, array $arr)
{
foreach($arr as $a) {
if (stripos($str,$a) !== false) return true;
}
return false;
}
?>