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,993
  • Total Topics: 21,324
  • Online today: 363
  • 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

This website is proudly hosted on Crocweb Cloud Website Hosting.