summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2017-06-20 21:58:46 +0100
committerLuke Bratch <luke@bratch.co.uk>2017-06-20 21:58:46 +0100
commitc26eeb7fb74886d0d003c63bb97e8f396cf05ccc (patch)
tree51431f3e325d2cb09901365e72b1c9300b197367 /index.php
Initial import
Diffstat (limited to 'index.php')
-rw-r--r--index.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..a9f4db2
--- /dev/null
+++ b/index.php
@@ -0,0 +1,90 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
+<html>
+
+<head>
+
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+
+<?php
+
+libxml_use_internal_errors(true);
+date_default_timezone_set("UTC");
+
+file_put_contents("time-index.txt", date("U"));
+
+$dom = new DOMDocument;
+$dom->loadHTML(file_get_contents("http://www.gov.je/weather/Pages/Jersey-Forecast.aspx"));
+
+$divs = $dom->getElementsByTagName("div");
+
+$day = 0;
+
+$valid = array();
+$temp = array();
+$misc = array();
+
+foreach ($divs as $div) {
+ if ($day > 2) {
+ break;
+ }
+
+ foreach ($div->attributes as $attr) {
+ if ($attr->nodeValue == "forecastValid") {
+ array_push($valid, $div->nodeValue);
+ $day++;
+ }
+
+ if ($attr->nodeValue == "forecastText" || $attr->nodeValue == "forecastText last") {
+ array_push($misc, $div->nodeValue);
+ }
+
+ if ($attr->nodeValue == "main") {
+ $spans = $div->getElementsByTagName("span");
+ foreach ($spans as $span) {
+ foreach ($span->attributes as $sattr) {
+ if ($sattr->nodeValue == "temp" || $sattr->nodeValue == "currentc") {
+ array_push($temp, $span->nodeValue);
+ }
+ }
+ }
+ }
+ }
+
+}
+
+// Replace newlines with spaces, and strip multiple spaces
+for ($i = 0; $i < count($misc); $i++) {
+ $misc[$i] = preg_replace("/[\r\n]+/", " ", $misc[$i]);
+ $misc[$i] = preg_replace("/\s+/", " ", $misc[$i]);
+}
+
+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";
+echo "</head>\n\n";
+echo "<body>\n\n";
+
+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";
+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";
+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";
+echo "<strong>Summary:</strong> $misc[4]<br><br>\n";
+echo "<strong>Wind:</strong> $misc[5]</p>";
+
+?>
+
+</body>
+
+</html>