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) { |
004764
|
109 |
$forced = FALSE; |
JK |
110 |
|
8bd4d9
|
111 |
if(empty($arg)) { |
JK |
112 |
$arg = database::get($_GET['from'], 'pogoda', 'miasto'); |
|
113 |
if(empty($arg)) { |
|
114 |
$arg = GGapi::getPublicData(); |
|
115 |
$arg = trim($arg['city']); |
|
116 |
if(empty($arg)) { |
|
117 |
$arg = 'Warszawa'; |
|
118 |
$forced = TRUE; |
|
119 |
} |
8810b3
|
120 |
GGapi::putText('Nie ustawiono miasta (pomoc - wpisz: help miasto) - '.(!$forced ? 'na podstawie danych z katalogu publicznego ' : '').'wybieram miasto '.$arg."\n\n"); |
8bd4d9
|
121 |
} |
JK |
122 |
} |
|
123 |
|
|
124 |
$dane = @file_get_contents('http://www.google.pl/ig/api?weather='.urlencode(ucwords(funcs::utfToAscii($arg)))); |
|
125 |
if(!$dane) { |
|
126 |
GGapi::putText('Przepraszamy, nie udało się połączyć z serwisem'); |
|
127 |
return; |
|
128 |
} |
|
129 |
|
|
130 |
$dane = iconv('iso-8859-2', 'utf-8', $dane); |
|
131 |
|
|
132 |
$dane = @simplexml_load_string($dane); |
|
133 |
if(!$dane) { |
|
134 |
GGapi::putText('Przepraszamy, błąd przy pobieraniu danych'); |
|
135 |
return; |
|
136 |
} |
|
137 |
|
|
138 |
if($dane->weather->problem_cause) { |
|
139 |
GGapi::putText('Problem w serwisie bądź danego miasta nie ma w bazie'."\n\n".'Przykład:'."\n".'pogoda Warszawa'."\n".'pogoda Kraków'); |
|
140 |
return; |
|
141 |
} |
|
142 |
|
|
143 |
$short2day = array( |
|
144 |
'pon.' => 'Poniedziałek', |
|
145 |
'wt.' => 'Wtorek', |
|
146 |
'śr.' => 'Środa', |
|
147 |
'czw.' => 'Czwartek', |
|
148 |
'pt.' => 'Piątek', |
|
149 |
'sob.' => 'Sobota', |
|
150 |
'niedz.' => 'Niedziela', |
|
151 |
); |
|
152 |
|
|
153 |
$region = substr(strstr($dane->weather->forecast_information->city['data'], ', '), 2); |
|
154 |
$region = trim(str_replace('Voivodeship', '', $region)); |
|
155 |
if(isset(self::$wojewodztwa[$region])) { |
|
156 |
$region = 'województwo '.self::$wojewodztwa[$region]; |
|
157 |
} |
|
158 |
|
|
159 |
$miasto = trim((string)$dane->weather->forecast_information->postal_code['data']); |
|
160 |
if(($a=strpos($miasto, '-'))!==FALSE) { |
|
161 |
$miasto = substr($miasto, 0, $a).'-'.ucfirst(substr($miasto, $a+1)); |
|
162 |
} |
|
163 |
|
|
164 |
GGapi::putRichText('Pogoda dla miasta '.$miasto.', '.$region."\n\n", TRUE); |
|
165 |
|
|
166 |
GGapi::putRichText('Teraz'."\n", TRUE); |
8810b3
|
167 |
self::putIcon((string)$dane->weather->current_conditions->icon['data']); |
JK |
168 |
|
8bd4d9
|
169 |
$condition = (string)$dane->weather->current_conditions->condition['data']; |
caa802
|
170 |
GGapi::putRichText(($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'])); |
8bd4d9
|
171 |
|
JK |
172 |
$num = TRUE; |
|
173 |
foreach($dane->weather->forecast_conditions as $day) { |
|
174 |
GGapi::putRichText("\n\n".($num ? 'Później' : $short2day[(string)$day->day_of_week['data']])."\n", TRUE); |
8810b3
|
175 |
self::putIcon((string)$day->icon['data']); |
JK |
176 |
GGapi::putRichText(($day->condition['data'])."\n".'Temp. od '.($day->low['data']).'°C do '.($day->high['data']).'°C'); |
8bd4d9
|
177 |
$num = FALSE; |
JK |
178 |
} |
|
179 |
|
|
180 |
} |
|
181 |
|
|
182 |
static function cmd_miasto($name, $arg) { |
|
183 |
$arg = trim(funcs::utfToAscii($arg)); |
|
184 |
if(empty($arg)) { |
|
185 |
$arg = database::get($_GET['from'], 'pogoda', 'miasto'); |
|
186 |
if(!empty($arg)) { |
|
187 |
GGapi::putText('Aktualnie ustawione miasto to: '.$arg); |
|
188 |
return; |
|
189 |
} |
|
190 |
|
|
191 |
$arg = GGapi::getPublicData(); |
|
192 |
$arg = funcs::utfToAscii($arg['city']); |
|
193 |
|
|
194 |
if(empty($arg)) { |
|
195 |
GGapi::putText('Nie podano wymaganego argumentu '); |
|
196 |
GGapi::putRichText('miasto', FALSE, TRUE); |
|
197 |
return; |
|
198 |
} |
|
199 |
|
|
200 |
|
|
201 |
GGapi::putText('Z katalogu publicznego pobrano miasto '.$arg."\n\n"); |
|
202 |
} |
|
203 |
|
|
204 |
$data = @file_get_contents('http://ws.geonames.org/search?name='.urlencode($arg)); |
|
205 |
if($data) { |
|
206 |
$data = simplexml_load_string($data); |
|
207 |
if($data && $data->totalResultsCount > 0) { |
|
208 |
$data = $data->geoname[0]; |
|
209 |
} |
|
210 |
else |
|
211 |
{ |
|
212 |
GGapi::putText('Podane miasto nie zostało odnalezione!'); |
|
213 |
return; |
|
214 |
} |
|
215 |
} |
|
216 |
else |
|
217 |
{ |
|
218 |
GGapi::putText('Wystąpił błąd przy wyszukiwaniu miasta. Spróbuj ponownie później.'); |
|
219 |
return; |
|
220 |
} |
|
221 |
|
|
222 |
if(!$data->geonameId || $data->geonameId=='756135') { |
|
223 |
$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>'); |
|
224 |
} |
|
225 |
|
|
226 |
GGapi::putText('Miasto zostało ustawione na '.(string)$data->name); |
|
227 |
database::add($_GET['from'], 'pogoda', 'miasto', (string)$data->name); |
|
228 |
database::add($_GET['from'], 'pogoda', 'kraj', (string)$data->countryName); |
|
229 |
database::add($_GET['from'], 'pogoda', 'cc', (string)$data->countryCode); |
|
230 |
database::add($_GET['from'], 'pogoda', 'geo', array('lat' => (string)$data->lat, 'lon' => (string)$data->lng)); |
|
231 |
} |
|
232 |
} |
7954aa
|
233 |
?> |