From e80d67e983cb92a5ee8475dd0c112fb448c2cf16 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 13 Feb 2016 00:16:33 +0000
Subject: [PATCH] [mod_kino] Dostosowanie modułu do zmian na stronach źródłowych
---
modules/30_pogoda/handler.php | 62 ++++++++++++++++++++-----------
1 files changed, 40 insertions(+), 22 deletions(-)
diff --git a/modules/30_pogoda/handler.php b/modules/30_pogoda/handler.php
index 6394cd7..5a11706 100644
--- a/modules/30_pogoda/handler.php
+++ b/modules/30_pogoda/handler.php
@@ -2,12 +2,12 @@
require_once(dirname(__FILE__).'/api_geonames.php');
require_once(dirname(__FILE__).'/api_yrno.php');
-class bot_pogoda_module extends BotModule {
+class bot_pogoda_module implements BotModule {
function pogoda($msg, $params) {
$arg = trim($msg->args);
$out = new BotMsg();
-
+ $loc = FALSE;
if(empty($arg)) {
$msg->session->setClass('pogoda');
@@ -37,22 +37,13 @@
catch(Exception $e) {
}
+ $forced = FALSE;
if(empty($arg)) {
$arg = 'Warszawa';
$forced = TRUE;
}
$out->a('<p>Nie ustawiono miasta (pomoc - wpisz: help miasto) - '.(!$forced ? 'na podstawie danych z katalogu publicznego ' : '').'wybieram miasto '.$arg.'</p>'."\n\n");
-
- $loc = new api_geonames();
- $loc = $loc->search($arg);
-
- if($loc === FALSE) {
- return new BotMsg('Nie udało się pobrać danych o podanym miejscu - spróbuj ponownie za około 10 minut.');
- }
- elseif($loc === NULL) {
- return new BotMsg('Dla podanego miejsca nie udało się uzyskać współrzędnych geograficznych - spróbuj wpisać inną nazwę.');
- }
}
else
{
@@ -66,20 +57,33 @@
}
}
+ if($loc === FALSE) {
+ $loc = new api_geonames();
+ $loc = $loc->search($arg);
+
+ if($loc === FALSE) {
+ return new BotMsg('Nie udało się pobrać danych o podanym miejscu - spróbuj ponownie za około 10 minut.');
+ }
+ elseif($loc === NULL) {
+ return new BotMsg('Dla podanego miejsca nie udało się uzyskać współrzędnych geograficznych - spróbuj wpisać inną nazwę.');
+ }
+ }
+
$api = yrno_weather($loc['lat'], $loc['lng']);
if($api == FALSE) {
return new BotMsg('Nie udało się pobrać danych o pogodzie - spróbuj ponownie za około 10 minut.');
}
- $out->a('<p>Pogoda dla '.htmlspecialchars($loc->name).', '.htmlspecialchars($loc->countryName).'.</p>'."\n\n");
+ $out->a('<p>Pogoda dla '.htmlspecialchars($loc['name']).', '.htmlspecialchars($loc['countryName']).'.</p>'."\n\n");
- $icon = $api->symbols[$api->getCurrentIcon()];
+ $icon = (int)$api->getCurrentIcon();
$weather = $api->getCurrentWeather();
$out->a('<p><b>Teraz</b><br />'."\n"
- . $icon.'<br />'."\n"
+ . '<img src="./data/pogoda/'.$icon.'.png" /><br />'."\n"
+ . api_yrno_parse::$symbols[$icon].'<br />'."\n"
. 'Temp.: '.htmlspecialchars($weather['temp']).'°C<br />'."\n"
- . 'Wiatr: '.htmlspecialchars($weather['wind']).' km/h, '.$api->wind($weather['wind']).'<br />'."\n"
+ . 'Wiatr: '.htmlspecialchars($weather['wind_speed']).' km/h, '.api_yrno_parse::wind($weather['wind_dir']).'<br />'."\n"
. 'Ciśnienie: '.htmlspecialchars($weather['pressure']).' hPa</p>'."\n\n");
$when = time();
@@ -98,16 +102,28 @@
return $out;
}
+ function getHTMLforRange($data) {
+ return htmlspecialchars($data['from'].($data['from'] != $data['to'] ? '-'.$data['to'] : ''));
+ }
+
function getHTMLforWeather($name, $icons, $weather) {
$html = '<p><b>'.$name.'</b><br />'."\n";
+ $desc = array();
+ $curr = 0;
foreach($icons as $icon) {
- if(is_file('./data/pogoda/'.htmlspecialchars($icon).'.png')) {
- $html .= '<img src="./data/pogoda/'.htmlspecialchars($icon).'.png" alt="" /> ';
+ $icon = (int)$icon;
+ if(is_file('./data/pogoda/'.$icon.'.png')) {
+ $html .= '<img src="./data/pogoda/'.$icon.'.png" alt="" /> ';
+ if($icon != $curr) {
+ $desc[] = api_yrno_parse::$symbols[$icon];
+ $curr = $icon;
+ }
}
}
$html .= '<br />'."\n"
- . 'Temp.: '.$weather['temp']['from'].($weather['temp']['from'] != $weather['temp']['to'] ? '-'.$weather['temp']['to'] : '').'°C<br />'."\n"
- . 'Wiatr: '.$weather['wind']['from'].($weather['wind']['from'] != $weather['wind']['to'] ? '-'.$weather['wind']['to'] : '').' km/h</p>'."\n\n";
+ . implode(' / ', $desc).'<br />'."\n"
+ . 'Temp.: '.$this->getHTMLforRange($weather['temp']['day']).'°C (w nocy: '.$this->getHTMLforRange($weather['temp']['night']).'°C)<br />'."\n"
+ . 'Wiatr: '.$this->getHTMLforRange($weather['wind']['day']).' km/h (w nocy: '.$this->getHTMLforRange($weather['wind']['night']).' km/h)</p>'."\n\n";
return $html;
}
@@ -123,8 +139,10 @@
$arg = trim($msg->args);
}
+ $out = new BotMsg();
+
if(empty($arg)) {
- if(isset($this->session->miasto)) {
+ if(isset($msg->session->miasto)) {
return new BotMsg('Aktualnie ustawione miejsce to: '.htmlspecialchars($this->session->miasto).', '.htmlspecialchars($this->session->countryName));
}
@@ -145,7 +163,7 @@
}
else
{
- $out = new BotMsg();
+
}
$api = new api_geonames();
--
Gitblit v1.9.1