60 | | foreach($data as $line) { |
61 | | if(strpos($line, 'this.sw') === false) |
62 | | continue; |
63 | | if(strpos($line, 'swTempCel') !== false) |
64 | | continue; |
65 | | |
66 | | $line = trim($line); |
67 | | list($name, $value) = explode(' = "', $line); |
68 | | $name = substr($name, 7); |
69 | | $value = substr($value, 0, strlen($value) - 2); |
70 | | |
71 | | switch ($name) { |
72 | | case 'City': $this->city = $value; break; |
73 | | case 'SubDiv': $this->subdiv = $value; break; |
74 | | case 'Country': $this->country = $value; break; |
75 | | case 'Region': $this->region = $value; break; |
76 | | case 'Temp': $this->Temperature = $value; break; |
77 | | case 'CIcon': $this->CIcon = $value; break; |
78 | | case 'WindS': $this->WindSpeed = $value; break; |
79 | | case 'WindD': $this->WindDirection = $value; break; |
80 | | case 'Baro': $this->BarometricPressure = $value; break; |
81 | | case 'Humid': $this->Humidity = $value; break; |
82 | | case 'Real': $this->Real = $value; break; |
83 | | case 'UV': $this->UV = $value; break; |
84 | | case 'Vis': $this->Visibility = $value; break; |
85 | | case 'LastUp': $this->LastUpdated = $value; break; |
86 | | case 'ConText': $this->ConText = $value; break; |
87 | | case 'Fore': $this->Forecast = $this->readForecast($value); break; |
88 | | default: /* Weird, unknown type */ break; |
89 | | } |
90 | | } |
| 77 | // |
| 78 | // Technically we should include the partner id and key |
| 79 | // if this stops working, change to the following: |
| 80 | // http://xoap.weather.com/weather/local/".$this->acid."?cc=*&unit=F&dayf=5&prod=xoap&par=1036905921&key=f68c2657a4fd3e2e" |
| 81 | // may need to get a new one from http://www.weather.com/services/xmloap.html |
| 82 | // |
| 83 | $this->LastUpdated=$this->in("<lsup>","</lsup>",$data); |
| 84 | $dnaminfo = $this->in("<dnam>","</dnam>",$data); |
| 85 | $sep = strpos($dnaminfo, ','); |
| 86 | if($sep != false) { |
| 87 | $this->city = substr($dnaminfo, 0, $sep); |
| 88 | $this->country = substr($dnaminfo, $sep + 1, strlen($dnaminfo) - $sep - 1); |
| 89 | } |
| 90 | $cc = $this->in("<cc>","</cc>",$data); |
| 91 | $this->Temperature=$this->in("<tmp>","</tmp>",$cc); |
| 92 | $this->Real=$this->in("<flik>","</flik>",$cc); |
| 93 | $barinfo = $this->in("<bar>","</bar>",$cc); |
| 94 | $this->BarometricPressure=$this->in("<r>","</r>",$barinfo); |
| 95 | $windinfo = $this->in("<wind>","</wind>",$cc); |
| 96 | $this->WindSpeed = $this->in("<s>","</s>",$windinfo); |
| 97 | $this->WindDirection = $this->in("<t>","</t>",$windinfo); |
| 98 | $this->Humidity = $this->in("<hmid>","</hmid>",$cc); |
| 99 | $this->Visibility = $this->in("<vis>","</vis>",$cc); |
| 100 | $uvinfo = $this->in("<uv>","</uv>",$cc); |
| 101 | $this->UV = $this->in("<i>","</i>",$uvinfo); |
| 102 | $this->CIcon = $this->in("<icon>","</icon>", $cc); |
| 103 | $this->ConditionText = $this->in("<t>","</t>",$cc); |
| 104 | $this->Forecast = $this->readForecast($data); |
101 | | if (strlen($this->ConText) > 0) { |
102 | | $this->ConditionText = $this->ConText; |
103 | | foreach ($Weather_Types as $pair) { |
104 | | if ($pair[1] != $this->ConditionText) |
105 | | continue; |
106 | | $this->ConditionImage = $pair[0]; |
107 | | break; |
108 | | } |
109 | | if(strlen($this->ConditionImage) == 0) |
110 | | list($this->ConditionImage, $blah) = $Weather_Types[$this->CIcon]; |
111 | | } |
112 | | else { |
113 | | list($this->ConditionImage, $this->ConditionText) = $Weather_Types[$this->CIcon]; |
114 | | } |
115 | | $this->ConditionImage = (strlen($this->ConditionImage) > 0) ? $this->ConditionImage : 'unknown.png'; |
| 117 | // if (strlen($this->ConText) > 0) { |
| 118 | // $this->ConditionText = $this->ConText; |
| 119 | // foreach ($Weather_Types as $pair) { |
| 120 | // if ($pair[1] != $this->ConditionText) |
| 121 | // continue; |
| 122 | // $this->ConditionImage = $pair[0]; |
| 123 | // break; |
| 124 | // } |
| 125 | // if(strlen($this->ConditionImage) == 0) |
| 126 | // list($this->ConditionImage, $blah) = $Weather_Types[$this->CIcon]; |
| 127 | // } |
| 128 | // else { |
| 129 | // list($this->ConditionImage, $this->ConditionText) = $Weather_Types[$this->CIcon]; |
| 130 | // } |
| 131 | // $this->ConditionImage = (strlen($this->ConditionImage) > 0) ? $this->ConditionImage : 'unknown.png'; |
| 132 | $this->ConditionImage = $this->CIcon.".png"; |
150 | | // mktime uses 0-6; msnbc gives us 1-7; adjust msnbc to match mktime |
151 | | $dayofweek = $data[$i] - 1; |
152 | | $forecast = new Forecast($data[5 + $i],$dayofweek); |
153 | | $forecast->dayofweek = $dayofweek; |
154 | | list($forecast->DescImage,$forecast->DescText) = $Weather_Types[$data[15 + $i]]; |
155 | | $forecast->DescImage = (strlen($forecast->DescImage) > 0) ? $forecast->DescImage : 'unknown.png'; |
156 | | $forecast->DescText = (strlen($forecast->DescText) > 0) ? $forecast->DescText : t('Unknown') . ' (' . $data[15+$i] . ')'; |
157 | | if($this->use_metric == 'YES') { |
158 | | $forecast->HighTemperature = round((5/9) * ($data[20 + $i] - 32)); |
159 | | $forecast->LowTemperature = round((5/9) * ($data[40 + $i] -32 )); |
160 | | } else { |
161 | | $forecast->HighTemperature = $data[20 + $i]; |
162 | | $forecast->LowTemperature = $data[40 + $i]; |
| 165 | $data1 = $this->in("<day d=\"".$i,"</day>",$data); |
| 166 | $day = $this->in("<day d=\"".$i."\" t=\"","\" dt",$data); |
| 167 | $forecast = new Forecast($this->LastUpdated, $i); |
| 168 | switch ($day) { |
| 169 | case 'Sunday': $forecast->dayofweek = 0; break; |
| 170 | case 'Monday': $forecast->dayofweek = 1; break; |
| 171 | case 'Tuesday': $forecast->dayofweek = 2; break; |
| 172 | case 'Wednesday': $forecast->dayofweek = 3; break; |
| 173 | case 'Thursday': $forecast->dayofweek = 4; break; |
| 174 | case 'Friday': $forecast->dayofweek = 5; break; |
| 175 | case 'Saturday': $forecast->dayofweek = 6; break; |
| 177 | // $forecast->dayofweek = $i; |
| 178 | |
| 179 | $fc = $this->in("<part p=\"d\">","</part>",$data1); |
| 180 | $forecast->DescText = $this->in("<t>","</t>",$fc); |
| 181 | $icon = $this->in("<icon>","</icon>",$fc); |
| 182 | $forecast->DescImage = $icon.".png"; |
| 183 | |
| 184 | $forecast->HighTemperature = $this->in("<hi>","</hi>",$data1); |
| 185 | $forecast->LowTemperature = $this->in("<low>","</low>",$data1); |
| 186 | |
| 187 | if($this->use_metric == 'YES') { |
| 188 | if ($forecast->HighTemperature != 'N/A') { |
| 189 | $forecast->HighTemperature = round((5/9) * ($forecast->HighTemperature - 32)); |
| 190 | } |
| 191 | if ($forecast->LowTemperature != 'N/A') { |
| 192 | $forecast->LowTemperature = round((5/9) * ($forecast->LowTemperature -32 )); |
| 193 | } |
| 194 | } |