summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2017-06-20 22:31:22 +0100
committerLuke Bratch <luke@bratch.co.uk>2017-06-20 22:31:22 +0100
commit53cf517409b23428b8d64eb578ac1faa59bf83be (patch)
tree6a39d4e76499532328064cd7991979e2dfcc2017
parentc26eeb7fb74886d0d003c63bb97e8f396cf05ccc (diff)
Support Jersey Met's night mode, where only the minimum and current temperature is listed
-rw-r--r--index.php28
1 files changed, 25 insertions, 3 deletions
diff --git a/index.php b/index.php
index a9f4db2..27f88a6 100644
--- a/index.php
+++ b/index.php
@@ -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("°", "&deg;", $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>";