$Foreign = $tr->find('td', 5)->plaintext; $input_name = "Number Of Foreign Players"; $row->input_id = getInputId($conn, $input_name, "Social", 0, "number"); $row->value = $Foreign; if ($conn->query($row->insertQuery())) { $row->insertMessage($input_name); } $TeamValue_MLN€ = floatval(str_replace(",", ".", str_replace(" mln €", "", $tr->find('td', 6)->plaintext))); $input_name = "Team Value (MLN EURO)"; $row->input_id = getInputId($conn, $input_name, "Monetary", 1, "number"); $row->value = $TeamValue_MLN€; if ($conn->query($row->insertQuery())) { $row->insertMessage($input_name); } $AVGPlayerValue = floatval(str_replace(",", ".", str_replace(" mln €", "", $tr->find('td', 7)->plaintext))); $input_name = "Average Player Value (MLN EURO)"; $row->input_id = getInputId($conn, $input_name, "Monetary", 0, "number"); if ($conn->query($row->insertQuery())) { $row->insertMessage($input_name); } echo "<br>"; } } } echo "<b>Done parsing transfermarkt stats for league={$league_id} and year={$year}</b><br>"; } } echo '</div><div class="col-md-6">'; echo "Done Parsing<br>"; echo '<a href="home.html#eleven" class="btn btn-info" role="button">Continue</a>'; echo '</div></div>';
Parser for transfermarkt data. //Parameters extracted: N.Players, AgeAVG, N.ForeignPlayers, TeamValue_MLN€, PlayerValueAVG_MLN€ Needs to be executed after the other scripts since it's using tm_id //Run more than once: parse max one league per run **/ require 'helper.php'; error_reporting(0); $html = file_get_html("stadiums.html"); echo '<div class="row"><div class="col-md-6">'; echo "<b>Parsing transfermarkt stadiums </b><br>"; //result $input_id = getInputId($conn, "Stadium Capacity", "Social", 0, "number"); foreach ($html->find('table[class=items]') as $table) { echo "<br>New League<br>"; foreach (array_slice($table->find('tr'), 1) as $tr) { foreach ($tr->find('table') as $tab) { $tm_id = $tab->find('a', 1)->id; } $value = $tr->find('td[class=rechts]', 0)->plaintext * 1000; if ($value > 0) { //echo "$tm_id----------$value "; $row = new DataRow(); $row->getTMTeamId($conn, $tm_id); if ($row->team_id > 0) { $row->value = $value; $row->input_id = $input_id; echo $row->fixedInsertQuery() . " ";
if ($conn->query($row->insertQuery())) { $row->insertMessage($input_name); } $Foreign = $tr->find('td', 5)->plaintext; $input_name = "Number Of Foreign Players"; $row->input_id = getInputId($conn, $input_name, "Social"); $row->value = $Foreign; if ($conn->query($row->insertQuery())) { $row->insertMessage($input_name); } $TeamValue_MLN€ = floatval(str_replace(",", ".", str_replace(" mln €", "", $tr->find('td', 6)->plaintext))); $input_name = "Team Value (MLN €)"; $row->input_id = getInputId($conn, $input_name, "Monetary"); $row->value = $TeamValue_MLN€; if ($conn->query($row->insertQuery())) { $row->insertMessage($input_name); } $AVGPlayerValue = floatval(str_replace(",", ".", str_replace(" mln €", "", $tr->find('td', 7)->plaintext))); $input_name = "Average Player Value (MLN €)"; $row->input_id = getInputId($conn, $input_name, "Monetary"); if ($conn->query($row->insertQuery())) { $row->insertMessage($input_name); } echo "<br>"; } } } echo "<b>Done parsing transfermarkt stats for league={$league_id} and year={$year}</b><br>"; } } echo "<h1>Done Parsing TM_STATS</h1>";
function parseInput($conn, $name, $selector, $table, $dataArray, $type) { $inputArray = $dataArray; $input_id = getInputId($conn, $name, $type); $i = 0; foreach ($table->find("{$selector}") as $element) { $inputArray[$i]->value = floatval($element->plaintext); $inputArray[$i]->input_id = $input_id; $i++; } foreach ($inputArray as $row) { if ($conn->query($row->insertQuery())) { $row->insertMessage($name); } } }
function input_config($userid) { $out = "<div class='lightbox' style='margin-bottom:20px;'>"; $out .= '<h3>2) Input Configuration:</h3>'; if (isset($_POST["form"])) { $form = $_POST["form"]; } else { $form = 0; } if ($form == 1 || $form == 2) { $input = $_POST["input"]; $out .= "<h3>" . $input . "</h3>"; $inputProcessList = getInputProcessList($userid, $input); // Form 2 is process addition ------------------------------------------ if ($form == 2) { $processType = $_POST["sel"]; // get process type $arg = $_POST["arg"]; $out .= "<h2>here: " . $processType . " arg:" . $arg . "</h2>"; // get feed name or scaler, offset etc if ($processType == 1 || $processType == 4 || $processType == 5 || $processType == 7 || $processType == 8) { $name = $arg; $id = getFeedId($userid, $name); if ($id == 0) { // Checks if feed of feed name arg exists $id = createFeed($userid, $name); // if not create feed and get its id } $arg = $id; } if ($processType == 6) { $arg = getInputId($userid, $arg); } $inputProcessList[] = array($processType, $arg); // Add the new process list entry saveInputProcessList($userid, $input, $inputProcessList); // Save the new process list } //---------------------------------------------------------------------- $out .= $this->view_processList($input, $inputProcessList); } else { $out .= "<p>Select an input to configure and map through to a feed</p>"; } $out .= "</div>"; return $out; }