Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
vB Weather Mk. 2 Details »»
vB Weather Mk. 2
Version: 1.00, by JJR512 JJR512 is offline
Developer Last Online: Jun 2006 Show Printable Version Email this Page

Version: 2.2.x Rating:
Released: 08-02-2002 Last Update: Never Installs: 59
 
No support by the author.

This is a post of a much-revised hack originally posted (by myself) here. I am posting this as a new hack because MSNBC, who the raw weather data is provided through, has changed their source provider (from AccuWeather to The Weather Channel), which required a retooling of the data parsing code, as well as completely new databases. I have also made obsolete the weather_functions.php file, moving the functions to admin/functions.php, simplifying the ability to show current weather data on any page (if desired). Finally, in what I'm sure will be welcome news to many people who have installed the original, I've completely rewritten the instructions, making them, as far as I can tell, much simpler.

If you are unfamiliar with the original: This hack provides current weather conditions and a five-day forecast to your members. Each member can select from over 34,000 cities, by narrowing down from region (like continents), country, and subdivision (like states). Each member can also select to see temperatures in Fahrenheit or Celsius, as well as metric or standard measurements for the other data.

A demo is available on my test board: http://www.jjr512.com/testboard/. I have set up an account for anyone to use to test it out (username: test; pw: test). If you are not logged in, you will see default weather on the home page (default is set to New York City), and cannot change settings (I forget if you can view a detailed forecast, though; you may be able to). If you do log in, you can change the settings for the test account, to see how it works.

***
If you have installed any previous version, you should completely uninstall it. Read the instructions and work backwards from there: Delete all templates added, remove changes to any existing templates (I forget if there were any or not), delete all new tables from the database, delete all new files added by the old hack. All have been changed to some extent, some more than others, and it would be easier to work from a clean slate. Especially since some of the template names have changes, so if you don't delete the old ones, they'll just be sitting there doing nothing at all. It is also vitally important to delete (or "drop") the tables--I believe there were six--you added for the original version. The new ones have different data and, for some, a different structure, so do not just empty them. Remove them totally.

Good luck!

Change Log
v1.1a: Current Version: Corrects a small error where an incorrect variable was used in the code to show the local time of the last update. If you already have v1.1, you only need to do the fix described in Post #82 below.
v1.1: Changes display of last update time to be the correct time in the user's own local time zone; previously, it was always Eastern Time (GMT-5) (Upgrade instructions are in Post #79 below). Also breaks the weather_city.sql into six smaller pieces (useful only to new installations; existing installations need not worry about this).
v1.0a: Adds instructions on how to add location to current weather on forums home page (changes to code added to index.php and forumhome_weather template).
v1.0: Original Release

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #182  
Old 09-10-2002, 12:03 AM
Gohan's Avatar
Gohan Gohan is offline
 
Join Date: Nov 2001
Location: The Netherlands
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by PsYc
Database error in vBulletin 2.2.7:

Invalid SQL: SELECT accid,city_title FROM weather_city WHERE subdivid=
mysql error: You have an error in your SQL syntax near '' at line 1

mysql error number: 1064


$cities = $DB_site->query("SELECT accid,city_title FROM weather_city WHERE subdivid=$current_subdiv[subdivid] ORDER BY city_title");


i think this query seems to complicate it..

i have created all tables and made the changes, i run it 4 times deleted it and made a fresh install... everytime i got this error, can anyone help?

--------------------------------------------------------
edit: ok fixed my errors, works great

* PsYc clicks install
same as my problem.. what did you fix?

==========================================

JJ.. Great hack!
Reply With Quote
  #183  
Old 09-10-2002, 11:59 AM
Gohan's Avatar
Gohan Gohan is offline
 
Join Date: Nov 2001
Location: The Netherlands
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello, someone can helped?
Reply With Quote
  #184  
Old 09-11-2002, 12:09 AM
Gohan's Avatar
Gohan Gohan is offline
 
Join Date: Nov 2001
Location: The Netherlands
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

*BUMP*
Reply With Quote
  #185  
Old 09-11-2002, 03:35 PM
PHiXTiT PHiXTiT is offline
 
Join Date: Sep 2002
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great hack! (5)

Only 2 problems.

1) The time is 40 minutes in the future.

2) There are no subdivisions in Canada such as Alberta, Ontario, etc, but all the cities are listed. All others are working for me.

BTW: Just wondering if you are planning on adding the option for users to select different .gif files when modifying settings?

Running on 2.2.7
Reply With Quote
  #186  
Old 09-11-2002, 03:45 PM
PsYc PsYc is offline
 
Join Date: Mar 2002
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Gohan


same as my problem.. what did you fix?

you have to put all .sql files via myphpadmin in the tables you created, only if you have transfered all content in these tables it will work

cities1-5.sql

region.sql

subdiv.sql

etc..
Reply With Quote
  #187  
Old 09-11-2002, 04:38 PM
Gohan's Avatar
Gohan Gohan is offline
 
Join Date: Nov 2001
Location: The Netherlands
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by PsYc
cities1-5.sql
Hmm.. i havent it but well weather_city5.sql


EDIT: Doesnt working!!! :tired:
Reply With Quote
  #188  
Old 09-13-2002, 07:25 AM
lemarsu's Avatar
lemarsu lemarsu is offline
 
Join Date: Aug 2002
Location: .eu
Posts: 73
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi,

I am looking in placing the weather in my vbindex, as described in post #107.

can anyone point me towards the template ? and all the other info you think I might need.

Thanks

LeMarsu
Reply With Quote
  #189  
Old 09-13-2002, 08:25 AM
Gohan's Avatar
Gohan Gohan is offline
 
Join Date: Nov 2001
Location: The Netherlands
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Open vbindex.php and find:

PHP Code:
// left & right templates 
add ABOVE:
PHP Code:
if ($weatherpage!=or !isset($weatherpage)) {

  
$usersettings $DB_site->query_first("SELECT * FROM weather_usersettings WHERE userid=$bbuserinfo[userid]");
  if (!isset(
$usersettings[userid])) {
    
$usersettings[accid] = "USNY0996";
    
$usersettings[tpc] = "1";
    
$usersettings[tps] = "1";
    
$DB_site->query("INSERT INTO weather_usersettings (userid,accid,tpc,tps) VALUES ('$bbuserinfo[userid]','$usersettings[accid]','$usersettings[tpc]','$usersettings[tps]')");
  }

  
$userdata $DB_site->query_first("SELECT * FROM weather_userdata WHERE userid=$bbuserinfo[userid]");
  
$datecut $userdata[time];
  if ((
time()-7200)>$datecut or $forceupdate=="yes") {
    
$rawdata fsockopen("www.msnbc.com",80,$num_error,$str_error,30);
    if(!
$rawdata) {
      
$weather[error_num] = $num_error;
      
$weather[error_str] = $str_error;
    } else {
      
fputs($rawdata,"GET /m/chnk/d/weather_d_src.asp?acid=$usersettings[accid] HTTP/1.0\n\n");

      while (!
feof($rawdata)) {
        
$getbit fgets($rawdata,4096);
        
$getbit trim($getbit)."\n";
        if (
substr($getbit,7,4) == "City") {
          
$weather[city] = substr($getbit,15,40);
          
$weather[city] = substr($weather[city],0,strlen($weather[city])-3);
        }
        if (
substr($getbit,7,6) == "SubDiv") {
          
$weather[subdiv] = substr($getbit,17,20);
          
$weather[subdiv] = substr($weather[subdiv],0,strlen($weather[subdiv])-3);
        }
        if (
substr($getbit,7,7) == "Country") {
          
$weather[country] = substr($getbit,18,20);
          
$weather[country] = substr($weather[country],0,strlen($weather[country])-3);
        }
        if (
substr($getbit,7,5) == "Temp ") {
          
$weather[temp] = substr($getbit,15,20);
          
$weather[temp] = substr($weather[temp],0,strlen($weather[temp])-3);
        }
        if (
substr($getbit,7,5) == "CIcon") {
          
$weather[cicon] = substr($getbit,16,20);
          
$weather[cicon] = substr($weather[cicon],0,strlen($weather[cicon])-3);
        }
        if (
substr($getbit,7,5) == "WindS") {
          
$weather[wind_spd] = substr($getbit,16,20);
          
$weather[wind_spd] = substr($weather[wind_spd],0,strlen($weather[wind_spd])-3);
        }
        if (
substr($getbit,7,5) == "WindD") {
          
$weather[wind_dir] = substr($getbit,16,20);
          
$weather[wind_dir] = substr($weather[wind_dir],0,strlen($weather[wind_dir])-3);
        }
        if (
substr($getbit,7,4) == "Baro") {
          
$weather[barometer] = substr($getbit,15,20);
          
$weather[barometer] = substr($weather[barometer],0,strlen($weather[barometer])-3);
        }
        if (
substr($getbit,7,5) == "Humid") {
          
$weather[humidity] = substr($getbit,16,20);
          
$weather[humidity] = substr($weather[humidity],0,strlen($weather[humidity])-3);
        }
        if (
substr($getbit,7,4) == "Real") {
          
$weather[realfeel] = substr($getbit,15,20);
          
$weather[realfeel] = substr($weather[realfeel],0,strlen($weather[realfeel])-3);
        }
        if (
substr($getbit,7,6) == "LastUp") {
          
$weather[lastup] = substr($getbit,17,25);
          
$weather[lastup] = substr($weather[lastup],0,strlen($weather[lastup])-3);
        }
        if (
substr($getbit,7,7) == "ConText") {
          
$weather[context] = substr($getbit,18,25);
          
$weather[context] = substr($weather[context],0,strlen($weather[context])-3);
        }
      }

      
// Location Info
      
$weatherdata[city] = $weather[city];
      
$weatherdata[subdiv] = $weather[subdiv];
      
$weatherdata[country] = $weather[country];

      
// Current Conditions
      
$weatherdata[temp] = convert_temp($weather[temp],$usersettings[tpc]);
      
$weatherdata[cicon] = $weather[cicon];
      
$weatherdata[wind_dir] = $weather[wind_dir];
      
$weatherdata[wind_spd] = convert_speed($weather[wind_spd],$usersettings[tps]);
      
$weatherdata[barometer] = convert_press($weather[barometer],$usersettings[tps]);
      
$weatherdata[humidity] = $weather[humidity];
      
$weatherdata[realfeel] = convert_temp($weather[realfeel],$usersettings[tpc]);
      
$weatherdata[lastup] = $weather[lastup];
      
$weatherdata[context] = $weather[context];

      
fclose($rawdata);
    }
  } else {
    
$weatherdata $DB_site->query_first("SELECT city,subdiv,country,temp,cicon,wind_dir,wind_spd,barometer,humidity,realfeel,lastup,context FROM weather_userdata WHERE userid=$bbuserinfo[userid]");
  }

  if (
$weatherdata[subdiv]) {
    
$weatherdata[showsubdiv] = "$weatherdata[subdiv], ";
  } else {
    
$weatherdata[showsubdiv] = "";
  }

  
$time_lastup strtotime($weatherdata[lastup]);
  
$weather[updatedate] = vbdate($dateformat,$time_lastup);
  
$weather[updatetime] = vbdate($timeformat,$time_lastup);

  eval(
"\$currentweather = \"".gettemplate("home_weather")."\";");

Create new template "home_weather":
PHP Code:
<tr>
    <
td width="165" bgcolor="{tablebordercolor}" >
    <
table width="100%" border="0" cellspacing="1" cellpadding="3">
    <
tr>
        <
td valign="top" bgcolor="{tableheadbgcolor}" align="center"><normalfont><font color="{categoryfontcolor}"><b>Weather</b></font></normalfont></td>
    </
tr>
    <
tr>
        <
td bgcolor="{firstaltcolor}" align="center">
        <
table bgcolor="{tablebordercolor}" border="0" cellpadding="4" cellspacing="1" width="100%" align="center">
        <
tr bgcolor="{categorybackcolor}">
            <
td align="center"><smallfont>$weatherdata[city]</smallfont></td>
        </
tr>
        <
tr bgcolor="{firstaltcolor}">
            <
td align="center"><smallfont><img src="{imagesfolder}/weather/$iconset/$weatherdata[cicon].gif" border="0" alt="$weatherdata[context]"><br>$weatherdata[context]</smallfont></td>
        </
tr>
        <
tr bgcolor="{secondaltcolor}">
            <
td align="center"><smallfont>Temperature:</smallfont><br><normalfont><b>$weatherdata[temp]</b></normalfont><br><smallfont>(Real Feel: <b>$weatherdata[realfeel]</b>)</smallfont></td>
        </
tr>
        <
tr bgcolor="{firstaltcolor}">
            <
td align="center"><smallfont><a href="weather.php?s=$session[sessionhash]&action=getdata">Detailed Forecast</a><br><a href="weather.php?s=$session[sessionhash]&action=modifysettings">Change Settings</a></smallfont></td>
        </
tr>
        </
table>
        </
td>
    </
tr>
    </
table>
    </
td>
</
tr
Open template "home_left" or "home_right" and add $currentweather (whatever want you put it)
Reply With Quote
  #190  
Old 09-13-2002, 08:48 AM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Gohan, those are your microstats:
"Page generated in 0.80156398 seconds (90.45% PHP - 9.55% MySQL) with 71 queries."
you could say goodbye to your server... the way it is now your page. over 40queries can bring easy to it's knees the server.
i hope you dont have a busy site, orelse you will have your account cancelled in no time by your host...
Reply With Quote
  #191  
Old 09-13-2002, 08:53 AM
Gohan's Avatar
Gohan Gohan is offline
 
Join Date: Nov 2001
Location: The Netherlands
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Page generated in 0.80983102 seconds (90.22% PHP - 9.78% MySQL) with 72 queries.
[Debug Mode OFF] [PHP v4.2.2] [GZIP disabled] [Server Load: 0.00 » 0.01 : 0.00]

so bad for server??
just no problem cus so fast server without lag.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:01 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05657 seconds
  • Memory Usage 2,433KB
  • Queries Executed 27 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete