<p>One web service that can find out the weather on the command line
is:</p>
<pre><code>$ curl wttr.in</code></pre>
<p>Inspired by this is the following script in PHP that uses data from
7timer.info</p>
<p>Available at <a
href="https://gist.github.com/macsplit">https://gist.github.com/macsplit</a></p>
<pre><code>&lt;?php

date_default_timezone_set(&#39;UTC&#39;);

$lon = &quot;-0.19759370325694858&quot;;
$lat = &quot;51.35956063540873&quot;;

$url = &quot;https://www.7timer.info/bin/civil.php?lon=$lon&amp;lat=$lat&amp;unit=metric&amp;ac=0&amp;output=json&quot;;

$weathers = [
    &#39;tsday&#39; =&gt; &quot;&#x2600;&#xFE0F; Hot Day&quot;,
    &#39;clearday&#39; =&gt; &quot;&#x2600;&#xFE0F; Clear Day&quot;,
    &#39;clearnight&#39; =&gt; &quot;&#x1F319; Clear Night&quot;,
    &#39;pcloudyday&#39; =&gt; &quot;&#x26C5; Partially Cloudy Day&quot;,
    &#39;pcloudynight&#39; =&gt; &quot;&#x2601;&#xFE0F; Partially Cloudy Night&quot;,
    &#39;mcloudyday&#39; =&gt; &quot;&#x1F325;&#xFE0F; Moderately Cloudy Day&quot;,
    &#39;mcloudynight&#39; =&gt; &quot;&#x2601;&#xFE0F; Moderately Cloudy Night&quot;,
    &#39;cloudyday&#39; =&gt; &quot;&#x2601;&#xFE0F; Cloudy Day&quot;,
    &#39;cloudynight&#39; =&gt; &quot;&#x2601;&#xFE0F; Cloudy Night&quot;,
    &#39;humidday&#39; =&gt; &quot;&#x1F321;&#xFE0F; Humid Day&quot;,
    &#39;humidnight&#39; =&gt; &quot;&#x1F321;&#xFE0F; Humid Night&quot;,
    &#39;lightrainday&#39; =&gt; &quot;&#x1F327;&#xFE0F; Lightly Rainy Day&quot;,
    &#39;lightrainnight&#39; =&gt; &quot;&#x1F327;&#xFE0F; Lightly Rainy Night&quot;,
    &#39;oshowerday&#39; =&gt; &quot;&#x1F327;&#xFE0F; Overcast Showery Day&quot;,
    &#39;oshowernight&#39; =&gt; &quot;&#x1F327;&#xFE0F; Overcast Showery Night&quot;,
    &#39;ishowerday&#39; =&gt; &quot;&#x1F327;&#xFE0F; Showery Day&quot;,
    &#39;ishowernight&#39; =&gt; &quot;&#x1F327;&#xFE0F; Showery Night&quot;,
    &#39;lightsnowday&#39; =&gt; &quot;&#x2744;&#xFE0F; Lightly Snowy Day&quot;,
    &#39;lightsnownight&#39; =&gt; &quot;&#x2744;&#xFE0F; Lightly Snowy Night&quot;,
    &#39;rainday&#39; =&gt; &quot;&#x1F327;&#xFE0F; Rainy Day&quot;,
    &#39;rainnight&#39; =&gt; &quot;&#x1F327;&#xFE0F; Rainy Night&quot;,
    &#39;snowday&#39; =&gt; &quot;&#x2744;&#xFE0F; Snowy Day&quot;,
    &#39;snownight&#39; =&gt; &quot;&#x2744;&#xFE0F; Snowy Night&quot;,
    &#39;rainsnowday&#39; =&gt; &quot;&#x1F328;&#xFE0F; Rainy and Snowy Day&quot;,
    &#39;rainsnownight&#39; =&gt; &quot;&#x1F328;&#xFE0F; Rainy and Snowy Night&quot;
];

$json = file_get_contents($url);
if (!$json) exit();
$obj = json_decode($json);
$init = DateTime::createFromFormat(&#39;YmdH&#39;, $obj-&gt;init)-&gt;getTimestamp();
$series = $obj-&gt;dataseries;
$now = time();
foreach ($series as $k =&gt; $point) {
    $timepoint = $point-&gt;timepoint;
    $timestamp = $init + ($timepoint * 3600);
    $diff = abs($timestamp - $now);
    $data[$diff] = $point;
}
$key = min(array_keys($data));
$measure = $data[$key];
$temperature = $measure-&gt;{&#39;temp2m&#39;};
$weather_desc = $weathers[$measure-&gt;weather];

echo &quot;$weather_desc $temperature&quot;.&quot;&#xB0;C\n&quot;;

?&gt;</code></pre>

<p><small><em>Editor's Note: Modified 2024-11-13 in line with comment #1</em></small></p>
