<!DOCTYPE html>
<html>
<head>
  <title>St. Gallen Temperatur</title>
</head>
<body>
  <h1>St. Gallen Temperatur</h1>

  <div id="temperature"></div>

  <script>
    // Setze API-Endpunkt für Wetterdaten von St. Gallen
    const apiEndpoint = 'https://data.sg.ch/api/records/1.0/search/?dataset=klima-stgallen&rows=1&sort=-datum&facet=datum&refine.datum=';

    // Füge aktuelles Datum zum API-Endpunkt hinzu
    const today = new Date();
    const year = today.getFullYear();
    const month = String(today.getMonth() + 1).padStart(2, '0');
    const day = String(today.getDate()).padStart(2, '0');
    const dateString = `${year}-${month}-${day}`;
    const apiEndpointWithDate = `${apiEndpoint}${dateString}`;

    // Führe eine HTTP-Anfrage zum API-Endpunkt aus
    fetch(apiEndpointWithDate)
      .then(response => response.json())
      .then(data => {
        // Hole die aktuelle Temperatur aus den Antwortdaten
        const temperature = data.records[0].fields.temp;

        // Zeige die aktuelle Temperatur auf der HTML-Seite an
        document.getElementById('temperature').innerHTML = `Die aktuelle Temperatur in St. Gallen beträgt ${temperature}°C.`;
      });
  </script>
</body>
</html>