1 | #!/usr/bin/php |
---|
2 | <?php |
---|
3 | // Script for mythweather to fetch weather information from weather.com |
---|
4 | |
---|
5 | |
---|
6 | // Load the weather classes |
---|
7 | require_once './WeatherSite.php'; |
---|
8 | require_once './Forecast.php'; |
---|
9 | |
---|
10 | |
---|
11 | $name = 'weather_com'; |
---|
12 | $version = 0.1; |
---|
13 | $author = 'William Stewart'; |
---|
14 | $email = 'level42@sympatico.ca'; |
---|
15 | $updateTimeout = 15*60; |
---|
16 | $retrieveTimeout = 30; |
---|
17 | $types = array('cclocation', 'station_id', |
---|
18 | 'observation_time', 'weather', |
---|
19 | 'temp', 'relative_humidity', |
---|
20 | 'wind_dir', 'wind_degrees', 'wind_speed', 'wind_gust', |
---|
21 | 'pressure', 'dewpoint', '3dlocation', '6dlocation', |
---|
22 | 'visibility', 'weather_icon', 'appt', 'wind_spdgst', |
---|
23 | 'high-0', 'high-1', 'high-2', 'high-3', 'high-4', 'high-5', |
---|
24 | 'low-0', 'low-1', 'low-2', 'low-3', 'low-4', 'low-5', |
---|
25 | 'icon-0', 'icon-1', 'icon-2', 'icon-3', 'icon-4', 'icon-5', |
---|
26 | 'date-0', 'date-1', 'date-2', 'date-3', 'date-4', 'date-5'); |
---|
27 | |
---|
28 | if ($argc == 1) { |
---|
29 | echo "No parameters supplied exiting..\n"; |
---|
30 | exit; |
---|
31 | } |
---|
32 | |
---|
33 | if ($argv[1] == "-v") { |
---|
34 | echo $name.",".$version.",".$author.",".$email."\n"; |
---|
35 | exit; |
---|
36 | } |
---|
37 | |
---|
38 | if ($argv[1] == "-T") { |
---|
39 | echo $updateTimeout.",".$retrieveTimeout."\n"; |
---|
40 | exit; |
---|
41 | } |
---|
42 | |
---|
43 | if ($argv[1] == "-t") { |
---|
44 | $size=sizeof($types); |
---|
45 | for($x = 0; $x < $size; $x++) { |
---|
46 | echo $types[$x]."\n"; |
---|
47 | } |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | if ($argv[1] == "-l") { |
---|
52 | foreach (file('../accid.dat') as $line) { |
---|
53 | list($ignore, $code, $name) = explode('::', $line); |
---|
54 | |
---|
55 | if (stripos($name,$argv[2]) !== FALSE) { |
---|
56 | echo $code."::".$name; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | exit; |
---|
61 | } |
---|
62 | |
---|
63 | $use_metric = 'NO'; |
---|
64 | |
---|
65 | for ($x = 1; $x < $argc; $x++) { |
---|
66 | if ($argv[$x] == "-d") { |
---|
67 | $dir = $argv[$x + 1]; |
---|
68 | } |
---|
69 | |
---|
70 | if ($argv[$x] == "-u") { |
---|
71 | if ($argv[$x + 1] == "SI") { |
---|
72 | $use_metric = 'YES'; |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | $loc = $argv[$argc - 1]; |
---|
78 | |
---|
79 | $weather = new WeatherSite($loc, " ", $use_metric); |
---|
80 | |
---|
81 | // Output the current conditions information |
---|
82 | echo "cclocation::".$weather->location."\n"; |
---|
83 | echo "station_id::".$loc."\n"; |
---|
84 | echo "observation_time::".$weather->LastUpdated."\n"; |
---|
85 | echo "weather::".$weather->ConditionText."\n"; |
---|
86 | echo "temp::".$weather->Temperature."\n"; |
---|
87 | echo "appt::".$weather->Real."\n"; |
---|
88 | echo "relative_humidity::".$weather->Humidity."\n"; |
---|
89 | if ($weather->WindDirection == "N") {echo "wind_dir::North\n";} |
---|
90 | elseif ($weather->WindDirection == "NE") {echo "wind_dir::Northeast\n";} |
---|
91 | elseif ($weather->WindDirection == "E") {echo "wind_dir::East\n";} |
---|
92 | elseif ($weather->WindDirection == "SE") {echo "wind_dir::Southeast\n";} |
---|
93 | elseif ($weather->WindDirection == "S") {echo "wind_dir::South\n";} |
---|
94 | elseif ($weather->WindDirection == "SW") {echo "wind_dir::Southwest\n";} |
---|
95 | elseif ($weather->WindDirection == "W") {echo "wind_dir::West\n";} |
---|
96 | elseif ($weather->WindDirection == "NW") {echo "wind_dir::Northwest\n";} |
---|
97 | else {echo "wind_dir::".$weather->WindDirection."\n";} |
---|
98 | |
---|
99 | echo "wind_degrees::".$weather->WindDegrees."\n"; |
---|
100 | echo "wind_speed::".$weather->WindSpeed."\n"; |
---|
101 | echo "wind_gust::".$weather->WindGust."\n"; |
---|
102 | echo "wind_spdgst::".$weather->WindSpeed." (".$weather->WindGust.")\n"; |
---|
103 | echo "pressure::".$weather->BarometricPressure."\n"; |
---|
104 | echo "dewpoint::".$weather->DewPoint."\n"; |
---|
105 | echo "visibility::".$weather->Visibility."\n"; |
---|
106 | echo "weather_icon::".$weather->ConditionImage."\n"; |
---|
107 | |
---|
108 | // Output the forecast information |
---|
109 | echo "3dlocation::".$weather->location."\n"; |
---|
110 | echo "6dlocation::".$weather->location."\n"; |
---|
111 | |
---|
112 | for ($x=0; $x < 6; $x++) { |
---|
113 | echo "high-".$x."::".$weather->Forecast[$x]->HighTemperature."\n"; |
---|
114 | echo "low-".$x."::".$weather->Forecast[$x]->LowTemperature."\n"; |
---|
115 | echo "icon-".$x."::".$weather->Forecast[$x]->DescImage."\n"; |
---|
116 | |
---|
117 | switch ($weather->Forecast[$x]->dayofweek) { |
---|
118 | case 0: echo "date-".$x."::Sunday\n"; break; |
---|
119 | case 1: echo "date-".$x."::Monday\n"; break; |
---|
120 | case 2: echo "date-".$x."::Tuesday\n"; break; |
---|
121 | case 3: echo "date-".$x."::Wednesday\n"; break; |
---|
122 | case 4: echo "date-".$x."::Thursday\n"; break; |
---|
123 | case 5: echo "date-".$x."::Friday\n"; break; |
---|
124 | case 6: echo "date-".$x."::Saturday\n"; break; |
---|
125 | } |
---|
126 | |
---|
127 | } |
---|
128 | |
---|