скрипт погоды и гороскопа для бота?

Discussion in 'PHP' started by cb93ka, 17 Apr 2007.

  1. cb93ka

    cb93ka Elder - Старейшина

    Joined:
    4 Jan 2007
    Messages:
    36
    Likes Received:
    13
    Reputations:
    3
    малость поумнел, но всеж скрипты у меня не заробили...

    поможет кто парсер http://informer.gismeteo.ru/xml/28573_1.xml - вот этого написать ? :-[

    //стыдно читать старые сообщения =\
     
  2. cb93ka

    cb93ka Elder - Старейшина

    Joined:
    4 Jan 2007
    Messages:
    36
    Likes Received:
    13
    Reputations:
    3
    PHP:
    <?php
    defined
    '_VALID_MOS' ) or die( 'Прямой доступ к файлам по этому адресу запрещен!' );
    global 
    $mosConfig_absolute_path;

    error_reporting(7);
    require_once( 
    $mosConfig_absolute_path '/includes/domit/xml_domit_lite_include.php' );

    $cache_time     intval$params->def'cache_time') );
    $cityid     $params->def'cityid');

    $week_days = array("","Вс.","Пн.","Вт.","Ср.","Чт.","Пт.","Сб.");
    $ru_monthes = array("","янв","фев","мар","апр","мая","июн","июл","авг","сен","окт","ноя","дек");
    $sutki = array("ночь","утро","день","вечер");
    $winds = array("сев","с-в","вост","ю-в","ю","ю-з","зап","с-з");
    $oblaka = array("ясно","малооблачно","облачно","пасмурно","дождь","ливень","снег","снег","гроза","нет данных об осадках","без осадков");

    $cache_file $mosConfig_absolute_path."/modules/mod_gismeteo/file.xml";
    $result_file $mosConfig_absolute_path."/modules/mod_gismeteo/result.txt";
    $template_file $mosConfig_absolute_path."/modules/mod_gismeteo/template.txt";

    if( 
    || !file_exists$result_file ) || ( time() - filemtime($result_file) > $cache_time ) ) {
        
    $gis_addr "http://informer.gismeteo.ru/xml/{$cityid}_1.xml";
        if( !
    $gis_stream fopen$gis_addr"rb" ) ) {
            echo 
    "Невозможно соединиться с богом погоды";
            return;
        }
        
    $gis_file '';
        do {
            
    $data fread($gis_stream8192 );
            if( 
    strlen$data ) == ) {
                break;
            }
            
    $gis_file .= $data;
        } while( 
    true );
        
    fclose($gis_stream);
        if( !
    $cache_stream fopen($cache_file"w") ) {
             echo 
    "Невозможно использовать кэш";
             return;
        }
        
    $cache_ok fwrite($cache_stream$gis_file);
        
    fclose($cache_stream);
        
    $xmlfile $cache_file;

        
    $template file_get_contents$template_file );
        
    $result "";
        if (
    file_exists$xmlfile )) {
            
    $xmlDoc =& new DOMIT_Lite_Document();
            
    $xmlDoc->resolveErrorstrue );
            if (
    $xmlDoc->loadXML$xmlfilefalsetrue )) {
                
    $element = &$xmlDoc->documentElement;
                if (
    $element->getTagName() == 'MMWEATHER') {
                    if( 
    $report = &$xmlDoc->getElementsByPath'REPORT') ) {
                        if( 
    $town $report->getElementsByPath'TOWN') ) {
                            for( 
    $k=1$k<5$k++ ) {
                                
    $forecast $town->getElementsByPath'FORECAST'$k ) ;
                                
    $day $forecast->getAttribute('day');
                                
    $month $ru_monthes[$forecast->getAttribute('month')];
                                
    $year $forecast->getAttribute('year');
                                
    $tod $sutki[$forecast->getAttribute('tod')];
                                
    $hour $forecast->getAttribute('hour');
                                
                                
    $temperature $forecast->getElementsByPath'TEMPERATURE');
                                
    $min_temperature $temperature->getAttribute('min');
                                
    $max_temperature $temperature->getAttribute('max');
        
                                
    $pressure $forecast->getElementsByPath'PRESSURE');
                                
    $min_pressure $pressure->getAttribute('min');
                                
    $max_pressure $pressure->getAttribute('max');
                                
                                
    $wind $forecast->getElementsByPath'WIND');
                                
    $wind_direction $winds$wind->getAttribute('direction') ];
                                
    $min_wind $wind->getAttribute('min');
                                
    $max_wind $wind->getAttribute('max');
                                
                                
    $relwet $forecast->getElementsByPath'RELWET');
                                
    $min_relwet $relwet->getAttribute('min');
                                
    $max_relwet $relwet->getAttribute('max');
                                
                                
    $heat $forecast->getElementsByPath'HEAT');
                                
    $min_heat $heat->getAttribute('min');
                                
    $max_heat $heat->getAttribute('max');
                                
                                
    $phenomena $forecast->getElementsByPath'PHENOMENA');
                                
    $cloudiness $oblaka[$phenomena->getAttribute('cloudiness')];
                                
    $precipitation $oblaka[$phenomena->getAttribute('precipitation')];
                                
                                eval(
    "\$result .= \"{$template}\";");
                            }
                        }
                    }
                } else echo 
    "Некорректный xml-документ";
            } else echo 
    "Невозможно открыть xml-документ";
        } else echo 
    'Не найден xml-файл';

        if( 
    $cache_time    && $result_stream fopen($result_file"w") ) {
            
    fwrite($result_stream$result);
            
    fclose($result_stream);
        }
        echo 
    $result;
        
    } else echo 
    file_get_contents$result_file );



    ?>
    вот модуль от мамбы, я попробывал сам его переделать но не получилось, даже при смене путей файлов и убирание хрени остальной.

    поправьте плз.