< >

wetter-api-php.php


Quell Code


<?php
$json = file_get_contents('https://api.weatherlink.com/v1/NoaaExt.json?user=001D0A00DE6A&pass=DEMO&%20%20apiToken=demo0a002bc5272033001d0a002bc527');
$obj = json_decode($json);
$stationname = $obj->davis_current_observation->station_name;
$location = $obj->location;
$observationtime = $obj->observation_time;
$tempc = $obj->temp_c;
$tempdayhighf = $obj->davis_current_observation->temp_day_high_f;
$tempdayhighc = ($tempdayhighf - 32) / 1.8;
$tempdaylowf = $obj->davis_current_observation->temp_day_low_f;
$tempdaylowc = ($tempdaylowf - 32) / 1.8;
$temphightime = $obj->davis_current_observation->temp_day_high_time;
$templowtime = $obj->davis_current_observation->temp_day_low_time;
$winddir = $obj->wind_dir;
$winddegrees = $obj->wind_degrees;
$windspeedkmh = $obj->wind_mph * 1.609;
$kmhtenmin = $obj->davis_current_observation->wind_ten_min_avg_mph * 1.609;
$kmhguststenmin = $obj->davis_current_observation->wind_ten_min_gust_mph * 1.609;
$humidity = $obj->relative_humidity;
$feelslike = $obj->windchill_c;
$raindailyin = $obj->davis_current_observation->rain_day_in;
$raindaily = $raindailyin * 25.4;
$rainseasonin = $obj->davis_current_observation->rain_year_in;
$rainseason = $rainseasonin * 25.4;
$barometer = $obj->pressure_string;
$barometertendency = $obj->davis_current_observation->pressure_tendency_string;
$dewpoint = $obj->dewpoint_c;
$cloudbase = ((($tempc - $dewpoint) / 2.5) * 304.8) + 900;
$sunrise = $obj->davis_current_observation->sunrise;
$sunset = $obj->davis_current_observation->sunset;
?>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="60" >
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
</head>
<body>
<center>
<table width="600px">
  <tbody align="left">
    <tr>
      <td colspan="3"><h3>Station Name: <?php echo $stationname ?></h3></td>
    </tr>
    <tr>
      <td colspan="3"><b>Location: <?php echo $location; ?></b></td>
    </tr>
    <tr>
      <td colspan="3"><b><?php echo $observationtime; ?></b></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
</tbody>

<tbody>
  <tr>
    <td width="25"><i class="fa fa-compass" style="font-size:25px;"></i></td>
    <td width="45%"><b>Wind Direction:</b></td>
    <td width="45%"> <?php echo $winddir; ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-compass" style="font-size:25px;"></i></td>
    <td width="45%"><b>Wind Degrees:</b></td>
    <td width="45%"><?php echo $winddegrees ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-wind" style="font-size:25px;"></i></td>
    <td width="45%"><b>Wind Speed (kmh):</b></td>
    <td width="45%"><?php echo round($windspeedkmh,1) ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-arrows-alt-h" style="font-size:25px;"></i></td>
    <td width="45%"><b>Wind 10 min AVG (kmh):</b></td>
    <td width="45%"><?php echo round($kmhtenmin,1); ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-arrow-up" style="font-size:25px;"></i></td>
    <td width="45%"><b>Wind 10 min gust (kmh):</b></td>
    <td width="45%"><?php echo round($kmhguststenmin,1); ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-cloud" style="font-size:25px;"></i></td>
    <td width="45%"><b>Estimated Cloudbase:</b></td>
    <td width="45%"><?php echo round($cloudbase,0); ?> meters</td>
  </tr>
  <tr>
    <td width="10%"><i class="fa fa-thermometer-half" style="font-size:25px;"></td>
    <td width="45%"></i><b>Temperature (C):</b></td>
    <td width="45%"><?php echo $tempc; ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-temperature-high" style="font-size:25px;"></i></td>
    <td width="45%"><b>Temperature HIGH (day):</b></td>
    <td width="45%"><?php echo round($tempdayhighc,1); ?> at <?php echo $temphightime; ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-temperature-low" style="font-size:25px;"></i></td>
    <td width="45%"><b>Temperature LOW (day):</b></td>
    <td width="45%"><?php echo round($tempdaylowc,1); ?> at <?php echo $templowtime; ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-grin-beam-sweat" style="font-size:25px;"></i></td>
    <td width="45%"><b>Humidity:</b> <?php echo $humidity; ?>%</td>
    <td width="45%"><b>Feels like:</b> <?php echo $feelslike; ?></td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-cloud-rain" style="font-size:25px;"></i></td>
    <td width="45%"><b>Rain past 24hrs:</b></td>
    <td width="45%"><?php echo round($raindaily,1); ?>&nbsp;mm</td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-tint" style="font-size:25px;"></i></td>
    <td width="45%"><b>Seaonal total:</b></td>
    <td width="45%"><?php echo round($rainseason,1); ?>&nbsp;mm</td>
  </tr>
  <tr>
    <td width="25"><i class="fa fa-chart-bar" style="font-size:25px;"></i></td>
    <td width="45%"><b>Barometer:</b> <?php echo $barometer; ?></td>
    <td width="45%"> <?php echo $barometertendency; ?></td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="49%"><i class="fa fa-sun" style="font-size:25px;"></i>&nbsp; <b>Sunrise:</b> <?php echo $sunrise; ?></td>
    <td width="49%"><i class="fa fa-sun" style="font-size:25px;"></i>&nbsp; <b>Sunset:</b> <?php echo $sunset; ?></td>
  </tr>
</tbody>
</table>
<i><br/>Script &copy Oliver Bross MBA -> <a href="https://www.oliverbross.com" target="_blank">www.oliverbross.com</a></i>
</center>
</body>
</html>