Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "uname";
- $password = "pwd";
- $dbname = "alerts";
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- date_default_timezone_set("America/Toronto");
- $hours = date(g);
- $minute = date(i);
- $ante= date(A);
- $time = "[$hours:$minute$ante]";
- $url = "https://weather.gc.ca/rss/warning/on-54_e.xml";
- $data= file_get_contents($url);
- $xml= simplexml_load_string($data);
- $json = json_encode($xml);
- $array = json_decode($json,TRUE);
- if ($array['entry']['title'] !== "No watches or warnings in effect, Pickering") {
- if ($array['entry']['title'] !== null) {
- $id0 = $array['entry']['id'];
- $sql = "SELECT id FROM alerts WHERE headline LIKE '$id0';";
- $result = $conn->query($sql);
- if ($result->num_rows == 0) {
- $flag0 = true;
- }
- $alert0string = $array['entry']['title'];
- $newTitle0 = str_replace(", Pickering", " for Ajax", $alert0string);
- $alert0desc = $array['entry']['summary'];
- preg_match("@\d{1,2}:\d{2} (AM|PM)@", $alert0desc, $matches0);
- $alert0time = $matches0[0];
- $alert0 = ($newTitle0.' at '.$alert0time);
- $alertfile = $alert0;
- } elseif ($array['entry'][0]['title'] !== null) {
- $id0 = $array['entry'][0]['id'];
- $sql = "SELECT id FROM alerts WHERE headline LIKE '$id0';";
- $result = $conn->query($sql);
- if ($result->num_rows == 0) {
- $flag0 = true;
- }
- $alert0string = $array['entry'][0]['title'];
- $newTitle0 = str_replace(", Pickering", " for Ajax", $alert0string);
- $alert0desc = $array['entry'][0]['summary'];
- preg_match("@\d{1,2}:\d{2} (AM|PM)@", $alert0desc, $matches0);
- $alert0time = $matches0[0];
- $alert0 = ($newTitle0.' at '.$alert0time);
- $alertfile = $alert0;
- }
- if ($array['entry'][1]['title'] !== null) {
- $id1 = $array['entry'][1]['id'];
- $sqla = "SELECT id FROM alerts WHERE headline LIKE '$id1';";
- $resulta = $conn->query($sqla);
- if ($resulta->num_rows == 0) {
- $flag1 = true;
- }
- $alert1string = $array['entry'][1]['title'];
- $newTitle1 = str_replace(", Pickering", " for Ajax", $alert1string);
- $alert1desc = $array['entry'][1]['summary'];
- preg_match("@\d{1,2}:\d{2} (AM|PM)@", $alert1desc, $matches1);
- $alert1time = $matches1[0];
- $alert1 = ($newTitle1.' at '.$alert1time);
- $alertfile = ($alert0.$alert1);
- }
- if ($array['entry'][2]['title'] !== null) {
- $id2 = $array['entry'][2]['id'];
- $sqlb = "SELECT id FROM alerts WHERE headline LIKE '$id2';";
- $resultb = $conn->query($sqlb);
- if ($resultb->num_rows == 0) {
- $flag2 = true;
- }
- $alert2string = $array['entry'][2]['title'];
- $newTitle2 = str_replace(", Pickering", " for Ajax", $alert2string);
- $alert2desc = $array['entry'][2]['summary'];
- preg_match("@\d{1,2}:\d{2} (AM|PM)@", $alert2desc, $matches2);
- $alert2time = $matches2[0];
- $alert2 = ($newTitle2.' at '.$alert2time);
- $alertfile = ($alert0.$alert1.$alert2);
- }
- } else {
- $alertfile = $array['entry']['title'];
- }
- if ($alert0 !== null && $flag0 == true) {
- echo $alert0;
- $sqlc = "INSERT INTO alerts (headline) VALUES ('$id0')";
- $resultc = $conn->query($sqlc);
- }
- if ($alert1 !== null && $flag1 == true) {
- echo $alert1;
- $sqld = "INSERT INTO alerts (headline) VALUES ('$id1')";
- $resultd = $conn->query($sqld);
- }
- if ($alert2 !== null && $flag2 == true) {
- echo $alert2;
- $sqle = "INSERT INTO alerts (headline) VALUES ('$id2')";
- $resulte = $conn->query($sqle);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement