-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.php
More file actions
70 lines (63 loc) · 2.46 KB
/
weather.php
File metadata and controls
70 lines (63 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
function realdegrees($in) {
$wd_deg = null;
switch ($in) {
case "N": { $wd_deg = 0; break; }
case "NNE": { $wd_deg = 22; break; }
case "NE": { $wd_deg = 45; break; }
case "ENE": { $wd_deg = 67 ; break; }
case "E": { $wd_deg = 90; break; }
case "ESE": { $wd_deg = 112; break; }
case "SE": { $wd_deg = 135; break; }
case "SSE": { $wd_deg = 157; break; }
case "S": { $wd_deg = 180; break; }
case "SSW": { $wd_deg = 202; break; }
case "SW": { $wd_deg = 225; break; }
case "WSW": { $wd_deg = 247; break; }
case "W": { $wd_deg = 270; break; }
case "WNW": { $wd_deg = 292; break; }
case "NW": { $wd_deg = 315; break; }
case "NNW": { $wd_deg = 337; break; }
}
return $wd_deg;
}
$data = file_get_contents("D:\\vader\\downld02.txt");
$lfv_data = file_get_contents("https://www.aro.lfv.se/Links/Link/ViewLink?TorLinkId=308&type=MET");
$lfv_data = strstr($lfv_data, "Södra delen</h1>");
$lfv_data = strip_tags($lfv_data);
preg_match_all('/I hela omr.*: ([0-9]{3})\/([0-9]+)kt ([-+][0-9]+)/', $lfv_data, $lfv_matches);
$data = preg_replace('/[ ]+/', ' ', $data);
$data = explode("\n", $data);
for($i = 3; $i < count($data); $i++) {
$row = explode(" ", $data[$i]);
if(count($row) < 10)
continue;
if($row[2] == '---')
continue;
$time = strtotime("20".$row[0]." ".$row[1]);
$wind_mean = $row[7];
$wind_dir = realdegrees($row[8]);
$wind_max = $row[10];
$temp = round($row[2]);
$result[] = array("time" => $time, "temperature" => $temp,
"wind" => array("mean" => $wind_mean, "max" => $wind_max,
"direction" => $wind_dir));
}
$lfv = null;
if (count($lfv_matches[2]) !== 0) {
$lfv = array(
"3000" => array("speed" => round($lfv_matches[2][2] * 0.514),
"direction" => (int)$lfv_matches[1][2],
"temperature" => (int)$lfv_matches[3][2]),
"1500" => array("speed" => round($lfv_matches[2][1] * 0.514),
"direction" => (int)$lfv_matches[1][1],
"temperature" => (int)$lfv_matches[3][1]),
"600" => array("speed" => round($lfv_matches[2][0] * 0.514),
"direction" => (int)$lfv_matches[1][0],
"temperature" => (int)$lfv_matches[3][0]));
}
$offset = 60 * 5;
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
header("Cache-Control: max-age=$offset, must-revalidate");
echo json_encode(array("station" => $result, "lfv" => $lfv));
?>