update: command for weather logging
This commit is contained in:
1 parent
a81c3adb10
commit
d1f77a92c5
3 files changed
+61
No files matched your search
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
include_once(__DIR__ . "/../controller/DataController.php");
|
||||
include_once(__DIR__ . "/../controller/DatabaseConnect.php");
|
||||
include_once(__DIR__ . "/../controller/DatabaseController.php");
|
||||
|
||||
$data = new getSpecificData();
|
||||
|
||||
print_r($data->getWeather());
|
||||
echo "";
|
||||
|
||||
$aktuell=($data->getWeather()['aktuell']);
|
||||
$min=($data->getWeather()['min']);
|
||||
$max=($data->getWeather()['max']);
|
||||
$gefuehlt=($data->getWeather()['gefuehlt']);
|
||||
$zeit=(date("d.m.Y H:i:s"));
|
||||
|
||||
DatabaseInsert(
|
||||
"Wetter",
|
||||
"ZEIT, AKTUELL, MIN, MAX, GEFUEHLT",
|
||||
$zeit,
|
||||
$aktuell,
|
||||
$min,
|
||||
$max,
|
||||
$gefuehlt,
|
||||
);
|
||||
@@ -2,6 +2,38 @@
|
||||
|
||||
class getSpecificData {
|
||||
|
||||
public function getWeather() {
|
||||
$url = "https://api.openweathermap.org/data/2.5/weather?q=Berlin,DE&APPID=5bc3e1a438c58fca444c4370ac0517b2&units=metric";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if(curl_errno($ch)) {
|
||||
echo "cURL Fehler: " . curl_error($ch);
|
||||
exit;
|
||||
}
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode === 200) {
|
||||
$data = json_decode($response, true);
|
||||
|
||||
return [
|
||||
'aktuell' => $data['main']['temp'],
|
||||
'min' => $data['main']['temp_min'],
|
||||
'max' => $data['main']['temp_max'],
|
||||
'gefuehlt' => $data['main']['feels_like']
|
||||
];
|
||||
} else {
|
||||
return "API Fehler. HTTP Code: " . $httpCode;
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserAgent(): string {
|
||||
return $_SERVER['HTTP_USER_AGENT'] ?? 'Unbekannt';
|
||||
}
|
||||
|
||||
@@ -77,6 +77,9 @@ $db_res = DatabaseShow(
|
||||
<p style="margin: 5px 0;"><strong>Database IP:</strong>
|
||||
<code><?= htmlspecialchars((new getSpecificData())->getDatabase()) ?></code>
|
||||
</p>
|
||||
<p style="margin: 5px 0;"><strong>Wetter:</strong>
|
||||
<code><?= htmlspecialchars((new getSpecificData())->getWeather()['aktuell']) ?></code>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user