This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
115 lines (95 loc) · 3.17 KB
/
index.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
<?php
$base = "https://api.overwatchleague.com/";
@mkdir("./data", 0755, true);
writeToFile("./data/about.json", get("about"));
$schedule = get("schedule");
writeToFile("./data/schedule.json", $schedule);
$schedule = json_decode($schedule, true);
$stages = [];
foreach ($schedule["data"]["stages"] as $s) {
foreach ($s["matches"] as $p) {
array_push($stages, $p["id"]);
}
}
echo "Stages: " . sizeof($stages) . "\n";
@mkdir("./data/match", 0755, true);
foreach ($stages as $id) {
echo "Stage: " . $id . "\n";
@mkdir("./data/match/" . $id, 0755, true);
writeToFile("./data/match/" . $id . "/data.json", get("match/" . $id));
humanSleep();
}
$games = [];
$stages = $schedule["data"]["stages"];
foreach ($stages as $i) {
foreach ($i["matches"] as $p) {
$mid = $p["id"];
$c = 1;
foreach ($p["games"] as $o) {
$tel = get("stats/matches/" . $mid . "/maps/" . $c);
echo "stats/matches/" . $mid . "/maps/" . $c . "\n";
if (!$tel) {
echo "failed to fetch content\n";
} else {
$dec = json_decode($tel, true);
writeToFile("./data/match/" . $mid . "/map-" . $c . ".json", $tel);
}
humanSleep();
$c++;
}
}
}
writeToFile("./data/streams.json", get("streams"));
humanSleep();
$teams = get("teams?expand=team.content&locale=en_US");
$decT = json_decode($teams, true);
writeToFile("./data/teams.json", $teams);
humanSleep();
@mkdir("./data/teams", 0755, true);
foreach ($decT["competitors"] as $team) {
echo "Team: " . $team["competitor"]["id"] . "\n";
writeToFile("./data/teams/" . $team["competitor"]["id"] . ".json", get("team/" . $team["competitor"]["id"]));
}
humanSleep();
writeToFile("./data/news.json", get("news"));
humanSleep();
writeToFile("./data/ranking.json", get("ranking"));
humanSleep();
writeToFile("./data/standings.json", get("standings"));
humanSleep();
writeToFile("./data/vods.json", get("vods"));
humanSleep();
writeToFile("./data/stats.json", get("stats/players?allPlayers=true"));
humanSleep();
writeToFile("./data/upcoming.json", get("live-match?expand=team.content&locale=en-us"));
humanSleep();
writeToFile("./data/maps.json", get("maps"));
humanSleep();
@mkdir("./data/players", 0755, true);
$players = get("players");
writeToFile("./data/players.json", $players);
humanSleep();
$playersJson = json_decode($players, true);
// print($players);
foreach ($playersJson["content"] as $player) {
echo "Player: " . $player["name"] . "\n";
writeToFile("./data/players/" . $player["id"] . ".json", get("players/" . $player["id"] . "?expand=stats,stats.ranks"));
}
echo "Done.\n";
function get($url)
{
global $base;
return @file_get_contents($base . $url);
}
function writeToFile($dir, $data)
{
if ($data == null || $data == "null" || $data == "") { echo "ERROR: " . $dir . "|" . $data . "\n"; return; }
$myfile = @fopen($dir, "w") or die("Unable to open file!");
fwrite($myfile, json_encode(json_decode($data, true), JSON_PRETTY_PRINT));
fclose($myfile);
echo "Done " . $dir . "\n";
}
function humanSleep()
{
// sleep(mt_rand(1, 3));
}