diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -19,6 +19,8 @@ $dom->loadHTML(file_get_contents("http://www.gov.je/weather/Pages/Jersey-Forecas $divs = $dom->getElementsByTagName("div"); $day = 0; +$maxcount = 0; // How many max temperatures we have encountered (minus one for each min temp) +$nightmode = 0; $valid = array(); $temp = array(); @@ -42,6 +44,14 @@ foreach ($divs as $div) { if ($attr->nodeValue == "main") { $spans = $div->getElementsByTagName("span"); foreach ($spans as $span) { + // If we get a min without a max, we're probably in night mode (only min and current listed) + if ($span->nodeValue == "Max") { + $maxcount++; + } else if ($span->nodeValue == "Min" && $max < 1) { + $nightmode = 1; + } else if ($span->nodeValue == "Min") { + $maxcount--; + } foreach ($span->attributes as $sattr) { if ($sattr->nodeValue == "temp" || $sattr->nodeValue == "currentc") { array_push($temp, $span->nodeValue); @@ -63,7 +73,11 @@ for ($i = 0; $i < count($temp); $i++) { // $temp[$i] = str_replace("°", "°", $temp[$i]); } -echo "<title>Max $temp[0], Min $temp[1], Cur $temp[2], $misc[0]</title>\n\n"; +if (!$nightmode) { + echo "<title>Max $temp[0], Min $temp[1], Cur $temp[2], $misc[0]</title>\n\n"; +} else { + echo "<title>Min $temp[0], Cur $temp[1], $misc[0]</title>\n\n"; +} echo "</head>\n\n"; echo "<body>\n\n"; @@ -71,7 +85,11 @@ echo "<p>Forecasts | <a href=\"./graphs.php\">Graphs</a></p>\n\n"; echo "<h2>Today</h2>\n\n"; echo "<p><em>$valid[0]</em><br><br>\n"; -echo "<strong>Max:</strong> $temp[0], <strong>Min:</strong> $temp[1], <strong>Current</strong>: $temp[2]<br><br>\n"; +if (!$nightmode) { + echo "<strong>Max:</strong> $temp[0], <strong>Min:</strong> $temp[1], <strong>Current</strong>: $temp[2]<br><br>\n"; +} else { + echo "<strong>Min:</strong> $temp[0], <strong>Cur:</strong> $temp[1]<br><br>\n"; +} echo "<strong>Summary:</strong> $misc[0]<br><br>\n"; echo "<strong>Visibility:</strong> $misc[1]<br><br>\n"; echo "<strong>Wind:</strong> $misc[2]<br><br>\n"; @@ -79,7 +97,11 @@ echo "<strong>Sea state:</strong> $misc[3]</p>\n\n"; echo "<h2>Tomorrow</h2>\n\n"; echo "<p><em>$valid[1]</em><br><br>\n"; -echo "<strong>Max</strong>: $temp[3], <strong>Min</strong>: $temp[4]<br><br>\n"; +if (!$nightmode) { + echo "<strong>Max</strong>: $temp[3], <strong>Min</strong>: $temp[4]<br><br>\n"; +} else { + echo "<strong>Max</strong>: $temp[2], <strong>Min</strong>: $temp[3]<br><br>\n"; +} echo "<strong>Summary:</strong> $misc[4]<br><br>\n"; echo "<strong>Wind:</strong> $misc[5]</p>"; |