commit | author | age
|
8bd4d9
|
1 |
<?php |
JK |
2 |
class pogoda implements module { |
|
3 |
static $wojewodztwa = array( |
|
4 |
'Kuiavia-Pomerania' => 'kujawsko-pomorskie', |
|
5 |
'Kuyavian-Pomeranian' => 'kujawsko-pomorskie', |
|
6 |
'Kujawsko-Pomorskie' => 'kujawsko-pomorskie', |
|
7 |
|
|
8 |
'Lesser Poland' => 'małopolskie', |
|
9 |
|
|
10 |
'Lodz' => 'łódzkie', |
|
11 |
'Łódź' => 'łódzkie', |
|
12 |
|
|
13 |
'Lower Silesia' => 'dolnośląskie', |
|
14 |
'Lower Silesian' => 'dolnośląskie', |
|
15 |
|
|
16 |
'Lublin' => 'lubelskie', |
|
17 |
'Lubelskie' => 'lubelskie', |
|
18 |
|
|
19 |
'Lubuskie' => 'lubuskie', |
|
20 |
|
|
21 |
'Mazovia' => 'mazowieckie', |
|
22 |
'Masovian' => 'mazowieckie', |
|
23 |
'Mazowieckie' => 'mazowieckie', |
|
24 |
|
|
25 |
'Opole' => 'opolskie', |
|
26 |
|
|
27 |
'Subcarpathia' => 'podkarpackie', |
|
28 |
'Podkarpackie' => 'podkarpackie', |
|
29 |
|
|
30 |
'Podlachia' => 'podlaskie', |
|
31 |
|
|
32 |
'Pomerania' => 'pomorskie', |
|
33 |
'Pomorskie' => 'pomorskie', |
|
34 |
|
|
35 |
'Silesia' => 'śląskie', |
|
36 |
|
|
37 |
'Swietokrzyskie' => 'świętokrzyskie', |
|
38 |
|
|
39 |
'Warmia and Masuria' => 'warmińsko-mazurskie', |
|
40 |
|
|
41 |
'Western Pomerania' => 'zachodniopomorskie', |
|
42 |
|
|
43 |
'Greater Poland' => 'wielkopolskie', |
|
44 |
'Wielkopolskie' => 'wielkopolskie', |
|
45 |
); |
|
46 |
|
|
47 |
static function register_cmd() { |
|
48 |
return array( |
|
49 |
'pogoda' => 'cmd_pogoda', |
|
50 |
'p' => 'cmd_pogoda', |
|
51 |
'weather' => 'cmd_pogoda', |
|
52 |
'miasto' => 'cmd_miasto', |
|
53 |
'm' => 'cmd_miasto', |
|
54 |
'temp' => 'cmd_pogoda', |
|
55 |
'temperatura' => 'cmd_pogoda', |
|
56 |
); |
|
57 |
} |
|
58 |
|
|
59 |
static function help($cmd=NULL) { |
|
60 |
if($cmd === NULL) { |
|
61 |
GGapi::putRichText('pogoda ', TRUE); |
|
62 |
GGapi::putRichText('[miasto]', FALSE, TRUE); |
|
63 |
GGapi::putRichText("\n".' Podaje pogodę dla miasta'."\n"); |
|
64 |
|
|
65 |
GGapi::putRichText('miasto ', TRUE); |
|
66 |
GGapi::putRichText('miasto', FALSE, TRUE); |
|
67 |
GGapi::putRichText("\n".' Ustala domyślne miasto dla funkcji pogoda'."\n\n"); |
|
68 |
} |
|
69 |
elseif(substr($cmd, 0, 1)=='m') |
|
70 |
{ |
|
71 |
GGapi::putRichText('miasto ', TRUE); |
|
72 |
GGapi::putRichText('miasto', FALSE, TRUE); |
|
73 |
GGapi::putRichText(' (alias: '); |
|
74 |
GGapi::putRichText('m', TRUE); |
|
75 |
GGapi::putRichText(')'."\n".' Ustawia domyślne '); |
|
76 |
GGapi::putRichText('miasto', FALSE, TRUE); |
|
77 |
GGapi::putRichText(' dla funkcji pogoda dla danego numeru Gadu-Gadu.'); |
|
78 |
} |
|
79 |
else |
|
80 |
{ |
|
81 |
GGapi::putRichText('pogoda ', TRUE); |
|
82 |
GGapi::putRichText('miasto', FALSE, TRUE); |
|
83 |
GGapi::putRichText(' (alias: '); |
|
84 |
GGapi::putRichText('p', TRUE); |
|
85 |
GGapi::putRichText(')'."\n".' Podaje pogodę dla danego miasta na najbliższe dni. Domyślne miasto można ustawić komendą '); |
|
86 |
GGapi::putRichText('miasto', TRUE); |
|
87 |
} |
|
88 |
} |
|
89 |
|
8810b3
|
90 |
static function putIcon($icon) { |
JK |
91 |
if(!empty($icon)) { |
|
92 |
if(!file_exists('./data/pogoda/'.basename($icon))) { |
|
93 |
if(substr($icon, 0, 1) == '/') { |
|
94 |
$icon = 'http://www.google.com'.$icon; |
|
95 |
} |
|
96 |
$img = @file_get_contents($icon); |
|
97 |
if($img) { |
|
98 |
file_put_contents('./data/pogoda/'.basename($icon), $img); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
GGapi::putImage('./data/pogoda/'.basename($icon)); |
|
103 |
GGapi::putText("\n"); |
|
104 |
} |
|
105 |
|
|
106 |
} |
|
107 |
|
8bd4d9
|
108 |
static function cmd_pogoda($name, $arg) { |
JK |
109 |
if(empty($arg)) { |
|
110 |
$arg = database::get($_GET['from'], 'pogoda', 'miasto'); |
|
111 |
if(empty($arg)) { |
|
112 |
$arg = GGapi::getPublicData(); |
|
113 |
$arg = trim($arg['city']); |
|
114 |
if(empty($arg)) { |
|
115 |
$arg = 'Warszawa'; |
|
116 |
$forced = TRUE; |
|
117 |
} |
8810b3
|
118 |
GGapi::putText('Nie ustawiono miasta (pomoc - wpisz: help miasto) - '.(!$forced ? 'na podstawie danych z katalogu publicznego ' : '').'wybieram miasto '.$arg."\n\n"); |
8bd4d9
|
119 |
} |
JK |
120 |
} |
|
121 |
|
|
122 |
$dane = @file_get_contents('http://www.google.pl/ig/api?weather='.urlencode(ucwords(funcs::utfToAscii($arg)))); |
|
123 |
if(!$dane) { |
|
124 |
GGapi::putText('Przepraszamy, nie udało się połączyć z serwisem'); |
|
125 |
return; |
|
126 |
} |
|
127 |
|
|
128 |
$dane = iconv('iso-8859-2', 'utf-8', $dane); |
|
129 |
|
|
130 |
$dane = @simplexml_load_string($dane); |
|
131 |
if(!$dane) { |
|
132 |
GGapi::putText('Przepraszamy, błąd przy pobieraniu danych'); |
|
133 |
return; |
|
134 |
} |
|
135 |
|
|
136 |
if($dane->weather->problem_cause) { |
|
137 |
GGapi::putText('Problem w serwisie bądź danego miasta nie ma w bazie'."\n\n".'Przykład:'."\n".'pogoda Warszawa'."\n".'pogoda Kraków'); |
|
138 |
return; |
|
139 |
} |
|
140 |
|
|
141 |
$short2day = array( |
|
142 |
'pon.' => 'Poniedziałek', |
|
143 |
'wt.' => 'Wtorek', |
|
144 |
'śr.' => 'Środa', |
|
145 |
'czw.' => 'Czwartek', |
|
146 |
'pt.' => 'Piątek', |
|
147 |
'sob.' => 'Sobota', |
|
148 |
'niedz.' => 'Niedziela', |
|
149 |
); |
|
150 |
|
|
151 |
$region = substr(strstr($dane->weather->forecast_information->city['data'], ', '), 2); |
|
152 |
$region = trim(str_replace('Voivodeship', '', $region)); |
|
153 |
if(isset(self::$wojewodztwa[$region])) { |
|
154 |
$region = 'województwo '.self::$wojewodztwa[$region]; |
|
155 |
} |
|
156 |
|
|
157 |
$miasto = trim((string)$dane->weather->forecast_information->postal_code['data']); |
|
158 |
if(($a=strpos($miasto, '-'))!==FALSE) { |
|
159 |
$miasto = substr($miasto, 0, $a).'-'.ucfirst(substr($miasto, $a+1)); |
|
160 |
} |
|
161 |
|
|
162 |
GGapi::putRichText('Pogoda dla miasta '.$miasto.', '.$region."\n\n", TRUE); |
|
163 |
|
|
164 |
GGapi::putRichText('Teraz'."\n", TRUE); |
8810b3
|
165 |
self::putIcon((string)$dane->weather->current_conditions->icon['data']); |
JK |
166 |
|
8bd4d9
|
167 |
$condition = (string)$dane->weather->current_conditions->condition['data']; |
JK |
168 |
GGapi::putRichText($txt.($condition ? $condition."\n" : '').'Temp.: '.($dane->weather->current_conditions->temp_c['data']).'°C'."\n".($dane->weather->current_conditions->humidity['data'])."\n".($dane->weather->current_conditions->wind_condition['data'])); |
|
169 |
|
|
170 |
$num = TRUE; |
|
171 |
foreach($dane->weather->forecast_conditions as $day) { |
|
172 |
GGapi::putRichText("\n\n".($num ? 'Później' : $short2day[(string)$day->day_of_week['data']])."\n", TRUE); |
8810b3
|
173 |
self::putIcon((string)$day->icon['data']); |
JK |
174 |
GGapi::putRichText(($day->condition['data'])."\n".'Temp. od '.($day->low['data']).'°C do '.($day->high['data']).'°C'); |
8bd4d9
|
175 |
$num = FALSE; |
JK |
176 |
} |
|
177 |
|
|
178 |
} |
|
179 |
|
|
180 |
static function cmd_miasto($name, $arg) { |
|
181 |
$arg = trim(funcs::utfToAscii($arg)); |
|
182 |
if(empty($arg)) { |
|
183 |
$arg = database::get($_GET['from'], 'pogoda', 'miasto'); |
|
184 |
if(!empty($arg)) { |
|
185 |
GGapi::putText('Aktualnie ustawione miasto to: '.$arg); |
|
186 |
return; |
|
187 |
} |
|
188 |
|
|
189 |
$arg = GGapi::getPublicData(); |
|
190 |
$arg = funcs::utfToAscii($arg['city']); |
|
191 |
|
|
192 |
if(empty($arg)) { |
|
193 |
GGapi::putText('Nie podano wymaganego argumentu '); |
|
194 |
GGapi::putRichText('miasto', FALSE, TRUE); |
|
195 |
return; |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
GGapi::putText('Z katalogu publicznego pobrano miasto '.$arg."\n\n"); |
|
200 |
} |
|
201 |
|
|
202 |
$data = @file_get_contents('http://ws.geonames.org/search?name='.urlencode($arg)); |
|
203 |
if($data) { |
|
204 |
$data = simplexml_load_string($data); |
|
205 |
if($data && $data->totalResultsCount > 0) { |
|
206 |
$data = $data->geoname[0]; |
|
207 |
} |
|
208 |
else |
|
209 |
{ |
|
210 |
GGapi::putText('Podane miasto nie zostało odnalezione!'); |
|
211 |
return; |
|
212 |
} |
|
213 |
} |
|
214 |
else |
|
215 |
{ |
|
216 |
GGapi::putText('Wystąpił błąd przy wyszukiwaniu miasta. Spróbuj ponownie później.'); |
|
217 |
return; |
|
218 |
} |
|
219 |
|
|
220 |
if(!$data->geonameId || $data->geonameId=='756135') { |
|
221 |
$data = new SimpleXMLElement('<geoname><name>Warszawa</name><lat>52.25</lat><lng>21.0</lng><geonameId>756135</geonameId><countryCode>PL</countryCode><countryName>Poland</countryName></geoname>'); |
|
222 |
} |
|
223 |
|
|
224 |
GGapi::putText('Miasto zostało ustawione na '.(string)$data->name); |
|
225 |
database::add($_GET['from'], 'pogoda', 'miasto', (string)$data->name); |
|
226 |
database::add($_GET['from'], 'pogoda', 'kraj', (string)$data->countryName); |
|
227 |
database::add($_GET['from'], 'pogoda', 'cc', (string)$data->countryCode); |
|
228 |
database::add($_GET['from'], 'pogoda', 'geo', array('lat' => (string)$data->lat, 'lon' => (string)$data->lng)); |
|
229 |
} |
|
230 |
} |
7954aa
|
231 |
?> |