0

I have different cities pages on my website need to display there weather conditions. For example if some one goes to Capetown page its weather can be shown in the block. Please suggest if there is some website through which we can import feeds or any module.

2 Answers 2

1

Paste the below code inside the block . i suggest to take the Capetown name or its latitude and longitude from google code and pass it to the $weather_poin variable in code.

<?php

        $weather_poin = 'Your city name or cordinates from google (latitude and longitude)';

    $doc = new DOMDocument();
    $doc->load('http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query='.$weather_poin);
    /*for */ 
    $display_lacations = $doc->getElementsByTagName( "display_location" );
    foreach( $display_lacations as $display_lacation )
    {
    $full_adds = $display_lacation->getElementsByTagName( "full" );
    $full_add = $full_adds->item(0)->nodeValue;

    $con_coded = $display_lacation->getElementsByTagName( "country_iso3166" );
    $con_code = $con_coded->item(0)->nodeValue;

    $latituded = $display_lacation->getElementsByTagName( "latitude" );
    $latitude = $latituded->item(0)->nodeValue;

    $longituded = $display_lacation->getElementsByTagName( "longitude" );
    $longitude = $longituded->item(0)->nodeValue;

    $elevations = $display_lacation->getElementsByTagName( "elevation" );
    $elevation = $elevations->item(0)->nodeValue;


    $displ_1 = "<b>Location</b> -- <b>$full_add $con_code $state_na </b><br></br>";
    }

    $observation_times = $doc->getElementsByTagName( "observation_time" );
    $observation_time = $observation_times->item(0)->nodeValue;

    $observation_time_rfc822s = $doc->getElementsByTagName( "observation_time_rfc822" );
    $observation_time_rfc822 = $observation_time_rfc822s->item(0)->nodeValue;

    $local_times = $doc->getElementsByTagName( "local_time" );
    $local_time = $local_times->item(0)->nodeValue;

    $weathers = $doc->getElementsByTagName( "weather" );
    $weather = $weathers->item(0)->nodeValue;

    $temperature_strings = $doc->getElementsByTagName( "temperature_string" );
    $temperature_string = $temperature_strings->item(0)->nodeValue;

    $Fahrenheits = $doc->getElementsByTagName( "temp_f" );
    $Fahrenheit = $Fahrenheits->item(0)->nodeValue;

    $Celsiuss = $doc->getElementsByTagName( "temp_c" );
    $Celsius = $Celsiuss->item(0)->nodeValue;

    $relative_humiditys = $doc->getElementsByTagName( "relative_humidity" );
    $relative_humidity = $relative_humiditys->item(0)->nodeValue;

    $wind_strings = $doc->getElementsByTagName( "wind_string" );
    $wind_string = $wind_strings->item(0)->nodeValue;

    $wind_dirs = $doc->getElementsByTagName( "wind_dir" );
    $wind_dir = $wind_dirs->item(0)->nodeValue;

    //$displ_2 = '<b>Fahrenheit - </b> $Fahrenheit.&deg;F <br></br><b>Celsius</b> - </b> $Celsius.&deg;C <br></br><b>Relative humidity</b> -</b> $relative_humidity<br></br><b>Wind string</b> -</b> $wind_string <br></br><b>Wind Direction</b> -</b> $wind_dir<br>';
    $displ_2 = "<b>Fahrenheit - </b> ".$Fahrenheit.".&deg;F <br></br><b>Celsius</b> - </b> ".$Celsius.".&deg;C <br></br><b>Relative humidity</b> -</b>".$relative_humidity."<br></br><b>Wind string</b> -</b> ".$wind_string." <br></br><b>Wind Direction</b> -</b> ".$wind_dir."<br>";

    $iconss = $doc->getElementsByTagName( "icons" );
    foreach( $iconss as $iconst )
    {
    $icon_sets = $iconst->getElementsByTagName( "icon_set" );
    foreach( $icon_sets as $icon_setr )
    {
    $icon_urls = $icon_setr->getElementsByTagName( "icon_url" );
    $icon_url = $icon_urls->item(0)->nodeValue;
    }
    }
    $displ_3 = $icon_url;
    $WeaThValue.= "<br>";
    $imgURL = $displ_3;
    $result.= "<br>";
    $WeaThValue.= $displ_1;
    $WeaThValue.= $displ_2;
    print '<img src="'.$imgURL.'" border="0">'."".$WeaThValue;
    //print $WeaThValue;

?>

4
  • Thanks Dhinesh.ES your script really works well. Is there a possibility to take city name from URL. I have tried the following but its not working $url = $_SERVER["SCRIPT_NAME"]; $x = explode ("/" , $url); $pagename = $x[2]; $weather_poin = $pagename Mar 18, 2013 at 9:15
  • Why don't you use $_request["value"] here to take the city name from URL, Hope $_SERVER["SCRIPT_NAME"] will not make any sense.
    – Dhinesh.ES
    Mar 18, 2013 at 11:32
  • it worked now through $weather_poin = basename($_SERVER['REQUEST_URI']); Mar 18, 2013 at 13:37
  • Great.. have a great time..
    – Dhinesh.ES
    Mar 18, 2013 at 13:41
1

I guess Google must be down where you are (obviously you would have searched at least for "Drupal Weather" before you posted this question, which is the search term I used), so in the meantime...

Weather module

This module uses METAR (METeorological Aerodrome Report) data to display current weather conditions from anywhere in the world.

3
  • 1
    Thank You Clive I have also found this one drupal.org/project/weather_block was actually confused because of Smart IP thing mentioned there. Just noticed that we may also specify location in that. let me give a try to both of them. Mar 11, 2013 at 12:53
  • There's also Google Weather which might be worth a look...
    – Clive
    Mar 11, 2013 at 12:55
  • I did installed the Weather module and the Node Location module. Specifying the location for node and but Weather module not showing the weather according to the node location. Mar 13, 2013 at 9:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.