
19.11.2008, 23:13
|
|
Познающий
Регистрация: 08.11.2008
Сообщений: 31
С нами:
9213963
Репутация:
4
|
|
плагин берет погоду с gismeteo.ru
class weather {
static $towns = array(),
$refresh_delay = 3600,
$regexp = '~<a\shref="http:\/\/www.gismeteo.ru\/towns\/(\d{5}).htm">(.*?)<\/a>~';
static function Refresh() {
$result = '';
if ($sock = fsockopen("search.gismeteo.ru", 80) ) {
fputs ($sock, "GET http://search.gismeteo.ru/?req=listbycountry&country=%D0%EE%F1%F1%E8%FF&lang =rus HTTP/1.0\n");
fputs ($sock, "Connection: Keep-Alive\n".
"User-Agent: SteelBot/1.0 (http://steelbot.net)\n".
"Host: search.gismeteo.ru\n".
"Pragma: no-cache\n".
"Cache-Control: no-cache\n".
"Connection: close\n\n" );
while ( !feof($sock) ) {
$result .= fgets($sock, 1024);
}
preg_match_all(self::$regexp, $result, $matches);
foreach($matches[2] as $k=>$town_name) {
self::$towns[$matches[1][$k]] = $town_name;
}
fclose($sock);
echo "[weather] town list refreshed (".count(self::$towns)." towns).\n";
} else {
echo "[weather] ERROR: can't establish connection to search.gismeteo.ru\n";
}
SteelBot::TimerAdd(self::$refresh_delay, array('bashorg', 'RefreshLast'));
}
static function GetWeather($town) {
if ( empty($towm) ) {
// не указали город, выводим помощь по команде
} else {
$town_id = array_search($town);
if ($town_id == false) {
SteelBot::Msg("Нет информации о погоде в городе $town");
return;
}
$result = '';
if ($sock = fsockopen("www.gismeteo.ru", 80) ) {
fputs ($sock, "GET http://www.gismeteo.ru/towns/$town_id.htm HTTP/1.0\n");
fputs ($sock, "Connection: Keep-Alive\n".
"User-Agent: SteelBot/1.0 (http://steelbot.net)\n".
"Host: search.gismeteo.ru\n".
"Pragma: no-cache\n".
"Cache-Control: no-cache\n".
"Connection: close\n\n" );
while ( !feof($sock) ) {
$result .= fgets($sock, 1024);
}
// здесь парсим информацию о конкретном городе
//preg_match_all(self::$regexp, $result, $matches);
//здесь составляем информацию о погоде
$weather = '';
SteelBot::Msg($weather);
} else {
echo "[weather] ERROR: can't establish connection to search.gismeteo.ru\n";
}
}
}
}
SteelBot::RegisterCmd('weather', array('weather', 'GetWeather'), 1, 'weather город - узнать погоду')
Для завершения в нем нужно дописать парсер информации для конкретного города, например для http://www.gismeteo.ru/towns/22471.htm
;
Последний раз редактировалось Frize; 16.01.2009 в 13:21..
|
|
|