/
list_config.php
151 lines (131 loc) · 3.73 KB
/
list_config.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
header('Content-Type: application/json');
require('simple_html_dom.php');
require('../common/savejsonbackup.php');
date_default_timezone_set('UTC');
$now = new DateTime("now");
//echo 'now: '.$now->format('Y/m/d H:i:s').'<br>';
$string = file_get_contents($cachefilename);
if ($string) {
//echo $string;
$json1=json_decode($string,true);
if (array_key_exists('datetime', $json1)) {
//echo 'then: '.$json1['datetime'].'<br>';
$then = DateTime::createFromFormat('Y/m/d H:i:s', $json1['datetime']);
$then1 = $then->add(new DateInterval('PT2M'));
//echo 'then+1: '.$then1->format('Y/m/d H:i:s').'<br>';
if ($then1 > $now) {
echo $string;
return;
}
}
}
$clots = [
/*[
"url" => "http://real-time-ladder.appspot.com/lot/5649391675244544",
"type" => "realtime",
"url_type" => "motd_template"
],
[
"url" => "http://wl1v1-clot.appspot.com/lot/5629499534213120",
"type" => "multiday",
"url_type" => "motd_template"
],
[
"url" => "http://multi-day-ladder.appspot.com/lot/5629499534213120",
"type" => "multiday",
"url_type" => "motd_template"
],
[
"url" => "http://warladder.net",
"type" => "multiday",
"url_type" => "dutch"
]*/
];
$output = [];
$i = 0;
foreach ($clots as $clot) {
$output[$i] = [];
$output[$i]['url'] = $clot["url"];
$html = file_get_html($clot["url"]);
if ($html) {
switch($clot["url_type"]) {
case "motd_template":
//TODO: extract template info
$output[$i]['name'] = $html->find("h1", 0)->plaintext;
$output[$i]['players'] = count($html->find('.table',1)->find('tr'))-1;
$output[$i]['type'] = $clot["type"];
break;
case "dutch":
//TODO: check if there are other ladders listed in this page instead of just taking the first one
$output[$i]['name'] = $html->find('.table',0)->find('a',0)->plaintext;
$output[$i]['players'] = $html->find('.table',0)->find('a',1)->plaintext;
$output[$i]['type'] = $clot["type"];
break;
}
} else {
//echo $clot.' taking too long to reply<br>';
$output[$i]['error'] = 'timeout';
}
$i++;
}
//var_dump($output);
$json['ladders'] = $output;
$leagues = [
[
"url" => "https://www.warlight.net/Forum/166818-clan-league-8-links",
"name" => "Clan League 8",
"players" => "~300"
],
[
"url" => "https://www.warlight.net/Forum/164080-manager-league-season-2",
"name" => "Manager League 2",
"players" => "~150"
],
[
"url" => "https://www.warlight.net/Forum/159429-awp-world-tour-magazine",
"name" => "AWP World Tour",
"players" => "~128"
],
[
"url" => "https://www.warlight.net/Forum/147689-wsow-season-3-rules-call-participants?Offset=0",
"name" => "World Series of Warlight 3",
"players" => "~100"
],
[
"url" => "https://www.warlight.net/Forum/152771-small-earth-promotionrelegation-league-season-6",
"name" => "Small Earth Promotion/Relegation League 6",
"players" => "~80"
],
[
"url" => "https://www.warlight.net/Forum/146128-rp-clan-league-2-official-thread",
"name" => "RP Clan League 2",
"players" => "~80"
],
[
"url" => "https://www.warlight.net/Forum/149352-promotionrelegation-league-season-19",
"name" => "Promotion/Relegation League 19",
"players" => "~50"
],
[
"url" => "https://www.warlight.net/Forum/136968-multiattackers-league-season-iv?Offset=0",
"name" => "Multiattacker's League IV",
"players" => "~40"
],
[
"url" => "https://www.warlight.net/Forum/151215-warlight-world-champions-league-wwcl",
"name" => "Warlight World Champions League",
"players" => "36"
]
];
$i = 0;
foreach ($leagues as $league) {
$output2[$i] = [];
$output2[$i]['url'] = $league["url"];
$output2[$i]['name'] = $league["name"];
$output2[$i]['players'] = $league["players"];
$i++;
}
$json['leagues'] = $output2;
$json['datetime'] = $now->format('Y/m/d H:i:s');
?>