TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,992
  • Total Topics: 21,323
  • Online today: 476
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 195
  • Total: 195

[Block] Local Weather

Started by darkorical, March 19, 2009, 08:49:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

darkorical

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**

JPDeni

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. :)

darkorical

hmm good point with those kind of locations you get a error Ill see if I can fix it

darkorical

#3
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>'
;
}

JPDeni

:) Sounds like a good idea. With programming, there's always something.

darkorical

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

IchBin

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.

dry3210

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

dry3210

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? 

darkorical

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

dry3210

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

wilsy

I'm using this block in a slightly different way on two of my sites - thanks for the share ;)

sandmannd

What type of code do I put this in as? I've used PHP, java script and HTML and none of those work.  :o

dry3210

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. 

sandmannd

Nope, that doesn't get it to work for me either.

ZarPrime

#15
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

stigmartyr

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.

darkorical

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)

stigmartyr

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.

This website is proudly hosted on Crocweb Cloud Website Hosting.