TinyPortal

Development => Block Codes => Topic started by: darkorical on March 19, 2009, 08:49:19 PM

Title: [Block] Local Weather
Post by: darkorical on March 19, 2009, 08:49:19 PM
Since the weather blocks I found either by searching or looking in the index seemed either too flashy or busted (bad link) I put this together

better code further down

*Special Thanks to JPDeni for helping to pull the user location**
Title: Re: [Block] Local Weather
Post by: JPDeni on March 20, 2009, 12:05:53 AM
The only thing that might end up causing trouble is that people put in things other than their actual location. I often use "near Seattle" because no one except people around here have heard of the town I live in. One member of my board has "in front of the laptop again" and another one has "off with the fairies." I don't know what you'll get with those locations.

But it looks like good code anyway. :)
Title: Re: [Block] Local Weather
Post by: darkorical on March 20, 2009, 02:04:32 AM
hmm good point with those kind of locations you get a error Ill see if I can fix it
Title: Re: [Block] Local Weather
Post by: darkorical on March 20, 2009, 03:04:11 AM
alright here's a quick and dirty work around
basically it tells everyone that the better their location the more accurate their weather will be and if they have something like "in front of my laptop" or "drifting in obscurity" they wont get nasty looking errors


?><center>To get better results enter a more precise city and state</center><hr>
<?php
error_reporting
(0);
global 
$ID_MEMBER$context,$memberContext;
loadMemberData($ID_MEMBER);
loadMemberContext($ID_MEMBER);
if(
$memberContext[$ID_MEMBER]['location'] == ""){echo 'If you enter your City and State on your profile this block will show you your local weather.';}
else{
$xmlDoc = new DOMDocument();
$xmlDoc->load('http://www.google.com/ig/api?weather='.$memberContext[$ID_MEMBER]['location'].'');
$params=$xmlDoc->getElementsByTagName('weather');       
$params2 $params->item($k)->getElementsByTagName('current_conditions') ; 
     
$i=0// values is used to iterate categories
$params3 $params2->item($i)->getElementsByTagName('condition');
 
$params4 $params2->item($i)->getElementsByTagName('temp_f');
$params5 $params2->item($i)->getElementsByTagName('humidity');
$params6 $params2->item($i)->getElementsByTagName('icon');
$params7 $params2->item($i)->getElementsByTagName('wind_condition');
              echo 
'
<table>
    <tr>
<td rowspan="2" align="center" valign="center"><img src="http://www.google.com/ig'
.$params6->item($j)->getAttribute('data').'"></td>
<td>'
.$params3->item($j)->getAttribute('data').'</td>
</tr>
<tr>
<td>'
.$params4->item($j)->getAttribute('data').'Ã,°F</td>
</tr>
<tr>
<td colspan="2">'
.$params5->item($j)->getAttribute('data').'</td>
</tr>
<tr>
<td colspan="2">'
.$params7->item($j)->getAttribute('data').'</td>
</tr>
</table>'
;
}
Title: Re: [Block] Local Weather
Post by: JPDeni on March 20, 2009, 12:25:17 PM
:) Sounds like a good idea. With programming, there's always something.
Title: Re: [Block] Local Weather
Post by: darkorical on March 23, 2009, 05:03:19 AM
ok whats up with that I got an email saying there had been a reply to this thread and I get here and find nothing new
Title: Re: [Block] Local Weather
Post by: IchBin on March 23, 2009, 03:31:15 PM
Someone could have replied and then deleted their reply because they could have either posted in the wrong topic, or didn't want their post here anymore.
Title: Re: [Block] Local Weather
Post by: dry3210 on April 02, 2009, 05:12:06 PM
Added!  Had something like this a long time ago but it stopped working.  This is great

Although it doesn't load the entire forum when I change my location to something goofy which was sort of mentioned above.

A nice addition might be to add a link to "5 day forecast" or something.  Could even have that go to an article/page that was embedded still
Title: Re: [Block] Local Weather
Post by: dry3210 on April 02, 2009, 05:48:14 PM
Hmm...upon further use it stopped working altogether and wouldn't let the forum load right.

Perhaps google has issues with so many people from the same site repeatedly grabbing the weather info? 
Title: Re: [Block] Local Weather
Post by: darkorical on April 02, 2009, 07:24:08 PM
hmm I don't know my site is an intranet site that never has more than 10 people at a time and its hard coded with the location

Ill try to look into it
Title: Re: [Block] Local Weather
Post by: dry3210 on April 02, 2009, 09:31:48 PM
And I made it visible after hiding it for about an hour and now its working and good for the moment.

Weird. 

Awesome though so hopefully it'll keep working this time
Title: Re: [Block] Local Weather
Post by: wilsy on April 13, 2009, 12:11:15 AM
I'm using this block in a slightly different way on two of my sites - thanks for the share ;)
Title: Re: [Block] Local Weather
Post by: sandmannd on April 28, 2009, 02:11:07 AM
What type of code do I put this in as? I've used PHP, java script and HTML and none of those work.  :o
Title: Re: [Block] Local Weather
Post by: dry3210 on April 28, 2009, 03:52:52 AM
Quote from: sandmannd on April 28, 2009, 02:11:07 AM
What type of code do I put this in as? I've used PHP, java script and HTML and none of those work.  :o

PHP block


error_reporting(0);
global $ID_MEMBER, $context,$memberContext;
loadMemberData($ID_MEMBER);
loadMemberContext($ID_MEMBER);
if($memberContext[$ID_MEMBER]['location'] == ""){echo 'If you enter your City and State on your profile this block will show you your local weather.';}
else{
$xmlDoc = new DOMDocument();
$xmlDoc->load('http://www.google.com/ig/api?weather='.$memberContext[$ID_MEMBER]['location'].'');
$params=$xmlDoc->getElementsByTagName('weather');       
$params2 = $params->item($k)->getElementsByTagName('current_conditions') ;
     
$i=0; // values is used to iterate categories
$params3 = $params2->item($i)->getElementsByTagName('condition');
$params4 = $params2->item($i)->getElementsByTagName('temp_f');
$params5 = $params2->item($i)->getElementsByTagName('humidity');
$params6 = $params2->item($i)->getElementsByTagName('icon');
$params7 = $params2->item($i)->getElementsByTagName('wind_condition');
              echo '
<table>
    <tr>
<td rowspan="2" align="center" valign="center"><img src="http://www.google.com/ig'.$params6->item($j)->getAttribute('data').'"></td>
<td>'.$params3->item($j)->getAttribute('data').'</td>
</tr>
<tr>
<td>'.$params4->item($j)->getAttribute('data').'Ã,°F</td>
</tr>
<tr>
<td colspan="2">'.$params5->item($j)->getAttribute('data').'</td>
</tr>
<tr>
<td colspan="2">'.$params7->item($j)->getAttribute('data').'</td>
</tr>
</table>';
}


I think he added a line at the beginning or end that you don't need.  I forget. 
Title: Re: [Block] Local Weather
Post by: sandmannd on April 28, 2009, 08:35:52 PM
Nope, that doesn't get it to work for me either.
Title: Re: [Block] Local Weather
Post by: ZarPrime on April 28, 2009, 09:46:31 PM
I don't know why it isn't working for you.  Are you using the code in the fourth post in this topic?

It works fine for me except that the cloudy.png link is broken.  You have to make sure you have put a location into your Forum Profile Information.  And it has to be a reasonable location.  LA won't work but Los Angeles, CA probably will.

One reason I won't use it though is because it add 6 seconds to my page creation time.

ZarPrime
Title: Re: [Block] Local Weather
Post by: stigmartyr on May 01, 2009, 09:25:07 AM
So I noticed that the google xml feed already has the forecast in it, but the PHP block isn't calling it out?

Is there a way to include that forecast or at least a link to it?  I like the block and I'm using it on my site, just think it needs forecasting to be truly useful.
Title: Re: [Block] Local Weather
Post by: darkorical on May 13, 2009, 10:14:47 PM
Quote from: Ã,§tigmartyr on May 01, 2009, 09:25:07 AM
So I noticed that the google xml feed already has the forecast in it, but the PHP block isn't calling it out?

Is there a way to include that forecast or at least a link to it?  I like the block and I'm using it on my site, just think it needs forecasting to be truly useful.

yea there is a way
Step 1. Expand script to return the results of the forecast
Step 2. Embed new script into custom page
Step 3. Add link to forecast page at bottom of block

When I get a chance Ill work on step 1 but step 2 and 3 will be up to end user (Ill offer assistance tho)
Title: Re: [Block] Local Weather
Post by: stigmartyr on May 13, 2009, 10:16:03 PM
Quote from: darkorical on May 13, 2009, 10:14:47 PM
Quote from: Ã,§tigmartyr on May 01, 2009, 09:25:07 AM
So I noticed that the google xml feed already has the forecast in it, but the PHP block isn't calling it out?

Is there a way to include that forecast or at least a link to it?  I like the block and I'm using it on my site, just think it needs forecasting to be truly useful.

yea there is a way
Step 1. Expand script to return the results of the forecast
Step 2. Embed new script into custom page
Step 3. Add link to forecast page at bottom of block

When I get a chance Ill work on step 1 but step 2 and 3 will be up to end user (Ill offer assistance tho)

Sweet - I'd be HAPPY to do steps 2 and 3 :D  You're the man.  Thanks for helping out with this.