Fibinger Ádám
4 days ago ef54434d88f2caf5b1e35b30a9c7380af624d190
commit | author | age
a9e494 1 <?php
2 include 'vendor/autoload.php';
3
4 use TableGenerator\DataObject;
5 use Wargasz\FileHelper;
6
7 $nyers_json = file_get_contents('teams_20200712.json');
8 $json = json_decode($nyers_json, true);
9
10 if (!is_array($json))
11 {
12     echo "Nem jó a fájl!";
13     return false;
14 }
15
16 $csapatok = [];
17 $warning = [];
18
19 foreach ($json as $team)
20 {
21     $jatekosok = [];
22
23     foreach ($team['players'] as $playerName)
24     {
25         $jatekosok[] = $playerName['inGameName'];
26     };
27
28     $csapatok[] = [
29         'name'    => $team['name'],
30         'captain' => $team['captain']['inGameName'],
31         'players' => $jatekosok
32     ];
33
34     if (count($jatekosok) > 8)
35     {
36         $warning[] = [
37             'team' => $team['name'],
38             'msg'  => 'Túl sok játékos a csapatban!',
39         ];
40     }
41 }
42
43 $table = [];
44
45 foreach ($csapatok as &$csapat)
46 {
47     $teamFolderName = 'workdir/' . FileHelper::normalizeString($csapat['name']);
48     if (!file_exists($teamFolderName))
49     {
50         mkdir($teamFolderName, 0777, true);
51     }
52
53     // https://r6.tracker.network/profile/pc/Fiber.I
54     foreach ($csapat['players'] as $playerName)
55     {
56         $playerFileName = $teamFolderName . '/' . FileHelper::normalizeString($playerName) . '.html';
57
58         if (!file_exists($playerFileName))
59         {
60             $trackerUrl = 'https://r6.tracker.network/profile/pc/' . $playerName;
61
62             echo "Downloading: $trackerUrl => $playerFileName" . PHP_EOL;
63
64             if (!FileHelper::downloadFiles($trackerUrl, $playerFileName))
65             {
66                 echo "Cannot get: $trackerUrl" . PHP_EOL;
67             }
68         }
69
70         $player = new \Wargasz\TrackerHtmlParser($playerFileName);
71
72         $playerData = $player->getPlayerData($playerName);
73
74         $csapat['playerData'][$playerName] = $playerData;
75
76         $team = [
77             'team'    => $csapat['name'],
78             'captain' => $csapat['captain'] == $playerName,
79         ];
80
81         $table[] = array_merge($team, $playerData);
82     }
83 }
84
85 $cols = [
86     'team'          => 'Csapat Név',
87     'name'          => 'Név',
88     'captain'       => ['Kapitány',
89         function ($a, $originalRowData) {
90             return $a ? "Igen" : "Nem";
91         }
92     ],
93     'valid'         => [
94         'Valid',
95         function ($a, $originalRowData) {
96             return $a ? $originalRowData['level'] >= 100 ? "Igen" : "Nem-LVL" : "Nem-NoUser";
97         }
98     ],
99     'level'         => 'LvL',
100     'alias_history' => 'Alias history'
101 ];
102
103 $do = new DataObject($cols, $table);
104
105 $HTMLTable = (new \TableGenerator\Render\HTMLTable(['id' => 'ccup']))->setDataObject($do);
106 ob_start();
107 $HTMLTable->renderTable();
108 file_put_contents('result.html', ob_get_clean());