115 lines
4.5 KiB
PHP
Executable File
115 lines
4.5 KiB
PHP
Executable File
<?php
|
|
include("../../mysqlverbinden.php");
|
|
include("../rowforeach.php");
|
|
include("inc.php");
|
|
|
|
$bundesliga = file_get_contents("liga.txt");
|
|
$year = file_get_contents("saison.txt");
|
|
|
|
$reload=false;
|
|
|
|
// Paarungen holen
|
|
// HTTP-Request ausführen
|
|
$spieltag=getmaxtippspieltag()+1;
|
|
if($spieltag<=34){
|
|
$response = file_get_contents("https://api.openligadb.de/getmatchdata/bl".$bundesliga."/".$year."/".$spieltag, false);
|
|
|
|
if ($response === false) {
|
|
echo "<script>window.alert(`Fehler beim HTTP-Request(Z.41)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);</script>";
|
|
}
|
|
|
|
|
|
$responseData = json_decode($response, true); // Response auswerten
|
|
if ($responseData!=null) {
|
|
// Response-Data ist ok
|
|
// Wochentag und Uhrzeit überprüfen, also auch überprüfen, ob die Daten schon aktuell sind
|
|
$aktuell = false;
|
|
foreach ($responseData as $key => $match) {
|
|
|
|
// Datum in UTC einlesen
|
|
$date = new DateTime($match["matchDateTimeUTC"], new DateTimeZone('UTC'));
|
|
|
|
// In die Zeitzone Berlin konvertieren
|
|
$date->setTimezone(new DateTimeZone('Europe/Berlin'));
|
|
|
|
|
|
$diff = time()-$date->getTimestamp();
|
|
|
|
if ($diff >= -60 * 60 * 24 * 21) {
|
|
$aktuell = true;
|
|
}
|
|
|
|
}
|
|
if ($aktuell) {
|
|
// Daten sind aktuell genug, Paarungen in die Datenbank einfügen
|
|
$spieltag=getmaxtippspieltag()+1;
|
|
foreach ($responseData as $key => $match) {
|
|
|
|
$deadline = new DateTime($match["matchDateTimeUTC"], new DateTimeZone('UTC'));
|
|
|
|
// In die Zeitzone Berlin konvertieren
|
|
$deadline->setTimezone(new DateTimeZone('Europe/Berlin'));
|
|
|
|
$heim=$match["team1"]["shortName"];
|
|
$gast=$match["team2"]["shortName"];
|
|
|
|
|
|
mysqli_execute_query($db_id,"INSERT INTO `buli-paarungen` (`heim`,`gast`,`spieltag`,`deadline`) VALUES (?,?,?,?);",[$heim,$gast,$spieltag,$deadline->format('Y-m-d H:i:s')]);
|
|
$reload=true;
|
|
}
|
|
}
|
|
} else {
|
|
// Response ist kein JSON
|
|
// echo "<script>window.alert(`JSON-Response ungültig (Z.84)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);</script>";
|
|
}
|
|
|
|
}
|
|
|
|
if($spieltag>=34){
|
|
$spieltag=getmaxspieltag()+1;
|
|
if(srowforeach("SELECT COUNT(*) from `buli-results` where spieltag=?;",[$spieltag-1])[0][0]<9) $spieltag--;
|
|
$response = file_get_contents("https://api.openligadb.de/getmatchdata/bl".$bundesliga."/".$year."/".$spieltag, false);
|
|
|
|
|
|
if ($response === false) {
|
|
// echo "<script>window.alert(`Fehler beim HTTP-Request (Z.15)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);</script>";
|
|
}
|
|
|
|
$responseData = json_decode($response, true); // Response auswerten
|
|
if ($responseData) {
|
|
// Response-Data ist ok
|
|
foreach ($responseData as $key => $match) {
|
|
if ($match["matchIsFinished"]) {
|
|
// Spiel beendet, Ergebnisse in die Datenbank eintragen
|
|
$heim=$match["team1"]["shortName"];
|
|
$gast=$match["team2"]["shortName"];
|
|
$paarungsquery=srowforeach("SELECT `id` from `buli-paarungen` where spieltag=? AND heim=? AND gast=?;",[$spieltag,$heim,$gast]);
|
|
if(count($paarungsquery)==0) continue;
|
|
|
|
|
|
$paarungsid=$paarungsquery[0][0];
|
|
$score1=$match["matchResults"][1]["pointsTeam1"];
|
|
$score2=$match["matchResults"][1]["pointsTeam2"];
|
|
mysqli_execute_query($db_id,"INSERT INTO `buli-results` (paarung, score1,score2, spieltag) VALUES (?,?,?,?);",[$paarungsid,$score1,$score2,$spieltag]);
|
|
$reload=true;
|
|
}
|
|
}
|
|
} else {
|
|
// Response ist kein JSON
|
|
// echo "<script>window.alert(`JSON-Response ungültig (Z.29)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);</script>";
|
|
}
|
|
|
|
}
|
|
|
|
if(srowforeach("SELECT COUNT(`id`) from `buli-icons`;",[])[0][0]<9){
|
|
mysqli_execute_query($db_id,"TRUNCATE `buli-icons`;",[]);
|
|
$responseDataTeams=json_decode(file_get_contents("https://api.openligadb.de/getavailableteams/bl".$bundesliga."/".$year, false),true);
|
|
|
|
foreach($responseDataTeams as $key => $value){
|
|
$iconurl=$value["teamIconUrl"];
|
|
$name=$value["shortName"];
|
|
$image=file_get_contents($iconurl,false);
|
|
mysqli_execute_query($db_id,"INSERT INTO `buli-icons` (`team`,`img`) VALUES (?,?);",[$name,$image]);
|
|
|
|
}
|
|
} |