This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

DragnLord's weather script

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

DragnLord wrote:downgrade if you want to, new script has been posted for a while (before your post about "us" user errors)
3.6-b has no problems with Aussie requests.
erm, what part of this was difficult to understand?
A corrected script was posted after rosc2112 brought up the problems in Oz.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

rosc2112 wrote:
Alchera wrote: NSW, VIC, ACT, SA, NT, QLD, WA & TAS (all States as we're a Federation). :)
Well, that doesn't tell me what cities are in which State.
Alchera wrote: Anyway, I am endeavouring to downgrade this script to a version that actually once worked! Last version to function correctly was weather3.5.9-a.
This version works, just have to remove the extra States/Regions for the moment. Or learn Oz geography I guess ;)
Okies: Sydney NSW, Melbourne VIC, Adelaide SA, Perth WA, Darwin NT, Brisbane QLD & Canberra ACT. :)
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

diff file to add barometer

Post by rosc2112 »

Hi, DL, sorry if posting here is annoying. Perhaps you could set up a forum on your site for posts. I've not had any luck catching you on your irc server =)

This is a bit too long to dump in a channel anyway I think. I had a user request barometer and dewpoint stats so I attempted to add them to the script.

I managed to get the barometer reading into it, but for some reason, I'm not getting the dew point. I don't know why, since I'm using the same basic code to grab it, but the regexp is not finding it at all in the $wzout (I didn't dump the contents of $wzout to my log, I probably should. I assumed that 'Dew Point:' would be in there, since that segment is between 'Humidity:' and 'Wind:' in the raw html output).

Anyway, here's the diff file to add the barometer, and the segment for dew point:

Code: Select all

--- /home/geetob/work/weather3.6-a.tcl  Fri May  5 02:37:45 2006
+++ /home/geetob/scripts/weather.tcl    Sun May  7 03:05:24 2006
@@ -848,2 +845,4 @@
 ## wdir                        wind direction
+## pressure            barometer
+## dewpt               dew point
 
@@ -874,2 +873,4 @@
    set wfntemp ""
+   set pressure ""
+   set dewpt ""
 
@@ -996,2 +997,28 @@
         }
+       if {$dewpt == "" && [regexp Dew.Point: $wzout]} {
+               putcmdlog "hmm"
+               for {set j 0} {$j <= 5} {incr j} {
+                       set wzout [gets $wzsock]
+                       if {[regexp <b> $wzout]} {
+                               regexp {b>(.*?)</b>} $wzout match dewpt
+                               regsub -all {<([^<])*>} $dewpt {} dewpt
+                               break
+                       }
+               }
+               putcmdlog "dew $dewpt"
+               continue
+       }
+
+       if {$pressure == "" && [regexp Pressure: $wzout]} {
+               for {set j 0} {$j <=10} {incr j} {
+                       set wzout [gets $wzsock]
+                       if {[regexp <b> $wzout]} {
+                               regexp {b>(.*?)</b>} $wzout match pressure
+                               regsub -all {<([^<])*>} $pressure {} pressure
+                               lappend pressure2 $pressure
+                       }
+               }
+               continue
+       }
+
         if {$hindex == "" && [regexp {Heat Index} $wzout]} {
@@ -1181,2 +1209,11 @@
    }
+   if {[regexp {[0-9]} $pressure2] == 0} {
+       set pressure "\002Barometer:\002 NR"
+       set noreport "(No Report)"
+   } else {
+       set baro1 [lindex $pressure2 0]
+       set baro2 [lindex $pressure2 1]
+       set baro [format "\002Barometer:\002 %sin/%shPa" $baro1 $baro2]
+   }
+
    if {$wind == ""} { 
@@ -1230,2 +1267,3 @@
       $::wz_outmeth "$outtarg : \002Conditions:\002 $cond   \002Wind:\002 $outwind"
+      $::wz_outmeth "$outtarg : $baro"
    }

I'm also going to try to add the record highs/lows, and moonrise/moonset data. I'll post that if I'm successful :)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

another diff, add observed at, moonrise/moonset

Post by rosc2112 »

I ended up dumping the data to the log just to see what's going on about why I can't grab the Dew Point: data, it's apparently not even in the html output, I'm not sure what to change to get that segment, tried a few different things to get more data, but not having any luck. Same for the record lows/highs, its not in the $wzout data. I'm not very well versed on the socket code yet.

But on the good news side, I did get the Observed at, Moonrise and Moonset data into the script's output (yay :) I added the "observed at" because weather data for a particular locale is usually from miles away at a nearby station, so I thought it would be useful to know where the data is coming from.

And so, here's another diff file which is in addition to the one above to add the humidity and attempted dewpoint data:

Code: Select all

--- /home/geetob/work/done/in-use/weather.tcl   Mon May  8 03:47:26 2006
+++ ./weather.tcl       Mon May  8 05:24:04 2006
@@ -847,2 +847,5 @@
 ## dewpt               dew point
+## observed            location of weather observations
+## moonrise            moonrise
+## moonset             moonset
 
@@ -875,2 +878,5 @@
    set dewpt ""
+   set observed ""
+   set moonrise ""
+   set moonset ""
 
@@ -1022,3 +1026,12 @@
        }
-
+       if {$observed == "" && [regexp {Observed At:} $wzout]} {
+               for {set j 0} {$j <=3} {incr j} {
+                       set wzout [gets $wzsock]
+                       if {[regexp {<td class} $wzout]} {
+                               regexp {<td class.*>(.*?)</td>} $wzout match observed
+                               regsub -all {<([^<])*>} $observed {} observed
+                       }
+               }
+               continue
+       }
 
@@ -1086,2 +1097,12 @@
 ## Full Moon?
+       set i 0
+       while {[regexp {>Moon</td>} $wzout] == 0 && $i < 400} {
+               incr i
+               set wzout [gets $wzsock]
+       }
+       set wzout [gets $wzsock]
+       regexp {>(.*?)</td} $wzout match moonrise
+       set wzout [gets $wzsock]
+       regexp {>(.*?)</td} $wzout match moonset
+
 
@@ -1182,3 +1206,3 @@
    if {$updtime != ""} {
-       set outupd "\002Updated:\002"
+       set outupd "\002Observed at:\002"
    }
@@ -1254,3 +1278,3 @@
    }
-   $::wz_outmeth "$outtarg : \002$city\002 -- $localtime $outupd $updtime"
+   $::wz_outmeth "$outtarg : \002$city\002 -- $localtime $outupd $observed $updtime"
    if {$get_sr_f} {
@@ -1262,2 +1286,3 @@
       $::wz_outmeth "$outtarg : The moon $phase."
+      $::wz_outmeth "$outtarg : \002Moonrise:\002 $moonrise  \002Moonset:\002 $moonset"
       set get_mn_f 0
This is how it looks:

Code: Select all

Somers Point, New Jersey -- 5:35 AM EDT Observed at: Atlantic City, New Jersey  4:54 AM EDT
Temp:  52F/11C        Humidity: 67%    
Conditions: Overcast    Wind: (NE)  7mph/11kmh
Barometer: 30.10in/1019hPa

Moon data:

West Pittston, Pennsylvania -- 5:36 AM EDT Observed at: Avoca, Pennsylvania  4:54 AM EDT
The moon is Waxing Gibbous, 78% of moon illuminated.
Moonrise: 3:42 PM EDT  Moonset: 3:43 AM EDT
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

I'm sure you will have a lot of fun maintaining your script. :D
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I got the dew point data working, tabinated the script, removed some redunant code, fixed some bugs, etc. Posted here:

http://members.dandy.net/~fbn/weather.2112.tcl.txt
p
popmonkey
Voice
Posts: 6
Joined: Sat Apr 29, 2006 1:39 pm

Post by popmonkey »

how does one query for a city that consists of more than one word.

example: le mans fr

i tried:

Code: Select all

.wz le mans fr
.wz le+mans fr
.wz le%20mans fr
.wz "le mans" fr
.wz 'le mans' fr
.wz le\ mans fr
etc. etc. etc.

looking at the code it looks like you split on space so multi word cities are broken up incorrectly. wunderground's query uses standard url encoding.
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

I bet you didn't bother to check the website.

Code: Select all

http://www.wunderground.com/cgi-bin/findweather/getForecast?query=le+mans
wunderground.com has no reported current conditions for that location; go bug them about it, not me

The script works fine, there is no information available from the website which means no output to give.

Edit:
add

Code: Select all

set outupd ""
to procedure wz_socket to get the "no report" output (will be added to future version)
p
popmonkey
Voice
Posts: 6
Joined: Sat Apr 29, 2006 1:39 pm

Post by popmonkey »

DragnLord wrote:I bet you didn't bother to check the website.
of course i did! http://www.wunderground.com/cgi-bin/fin ... ry=le+mans works just fine.

as does http://www.wunderground.com/global/stations/07235.html

but for some reason the script isn't reading the data. i straced eggdrop and you do convert to the latter so it seems to be a page parsing issue if anything.

i'll grab the latest version of the script and try again.
p
popmonkey
Voice
Posts: 6
Joined: Sat Apr 29, 2006 1:39 pm

Post by popmonkey »

3.6-b works. 3.5.9-b did not.

i didn't see anything in the change history that said anything other than country codes had changed.

ok, happy now. thanks.
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

popmonkey wrote:http://www.wunderground.com/cgi-bin/fin ... ry=le+mans works just fine.

as does http://www.wunderground.com/global/stations/07235.html

but for some reason the script isn't reading the data. i straced eggdrop and you do convert to the latter so it seems to be a page parsing issue if anything.

i'll grab the latest version of the script and try again.
I see no current weather condition information on either of those pages for the script to grab.
Since the webpage has to show the conditions for the script to grab them, it returns nothing.
Refer your complaints to wunderground.com.
p
popmonkey
Voice
Posts: 6
Joined: Sat Apr 29, 2006 1:39 pm

Post by popmonkey »

there's forecast information but .wzf doesn't work

(btw, i noticed you updated the script to include the outupd "" already, thanks)
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

without current weather conditions, the script doesn't have what it needs to locate the forecast info
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

couple of bugs

Post by rosc2112 »

Found a couple of bugs, can't figure out how to fix em.

In the section where '-u' is checked for valid syntax, it does not return the error msg as it should.

Code: Select all

   set wz_tunit $wz_unit 
   if {[regexp -- {(-u )([imc])} $location match yoo wz_tunit]} { 
     set wz_tunit_reset 1 
     if {[regexp {[imc]} $wz_tunit] == 0} {
        puthelp "NOTICE $nick :Proper syntax for units is $::wzbind -u <imc> <city,state|zip> <country> ... ^BI^Bmperial, ^BM^Betric, or ^BC^Bombined.
        return 0
     }
     regsub -- {-u [imc] ?} $location {} location
   }
Another is, for some reason, sun and moon data is not returned for foreign countries, even though looking at the source html for their pages shows the same html format as for US locations. The only apparent difference is where its at on the page.

And, for the precipitation code, it doesn't close the socket on some of the errors/returns.
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

What version are you using?
I have not been able to reproduce those with the current version.

Perhaps some more information, such as what locations do not show sun and/or moon data.

What locations cause socket errors with precipitation?

The biggest question, why haven't you reported the bugs through the proper method?
Post Reply