Author |
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 11 2005 at 07:59 | IP Logged
|
|
|
Maybe the page serves differently from where you are?
I went to the site, pulled data for Amsterdam, and it looked fine from this end.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 12 2005 at 03:23 | IP Logged
|
|
|
TonyNo wrote:
Maybe the page serves differently from where you are? I went to the site, pulled data for Amsterdam, and it looked fine from this end. |
|
|
Well, when I execute the macro the values are simply not there... The macro runs fine... I have surfed with my explorer to the page with the address in the macro and saved the complete page... Maybe there is a difference...I will put it on my WEB-server:
Here is the link so you can compare with yours, the info is for Eindhoven:
Saved Wunderground page
Perhaps there is infact a difference...
cheerio
Peter
b.t.w. Have you read my EDIT on my last post of your Ping project?
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 12 2005 at 09:27 | IP Logged
|
|
|
I'll check it out.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 24 2005 at 08:57 | IP Logged
|
|
|
OK, here is one tweaked to work with your supplied HTML.
Replace the ph_readfile with the proper ph_geturl. Also, I have user messages that log the temp data and forecast instead of assigning them to variables.
Code:
insert into macroheader values ('GET WEATHER A','GET WEATHER',0,0,1);
insert into macrodetail values ('GET WEATHER A',1,15,'[LOCAL1]',NULL,'ph_readfile("getforecast.htm")',0);
insert into macrodetail values ('GET WEATHER A',2,15,'[LOCAL1]',NULL,'ph_replaceall( "[LOCAL1]", "~r", "" )',0);
insert into macrodetail values ('GET WEATHER A',3,15,'[LOCAL1]',NULL,'ph_replaceall( "[LOCAL1]", "~n", "" )',0);
insert into macrodetail values ('GET WEATHER A',4,15,'[LOCAL1]',NULL,'ph_replaceall( "[LOCAL1]", "~t", " " )',0);
insert into macrodetail values ('GET WEATHER A',5,15,'[LOCAL2]',NULL,'posw( ''[LOCAL1]'', ''<div style="font-size: 17px;'')',0);
insert into macrodetail values ('GET WEATHER A',6,36,'',NULL,'"[LOCAL2]"',0);
insert into macrodetail values ('GET WEATHER A',7,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", "<b>", [LOCAL2])+3',0);
insert into macrodetail values ('GET WEATHER A',8,15,'[LOCAL3]',NULL,'posw( "[LOCAL1]", "</b>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',9,15,'[LOCAL3]',NULL,'mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',10,15,'[LOCAL4]',NULL,'"The temperature is " + if( isnumber( "[LOCAL3]"), "[LOCAL3]", left( "[LOCAL3]", 2)) + " degrees"',0);
insert into macrodetail values ('GET WEATHER A',11,16,'',NULL,'if( posw( "[LOCAL1]", "Windchill:") = 0, 5, 1)',0);
insert into macrodetail values ('GET WEATHER A',12,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", "<nobr><b>", posw( "[LOCAL1]", "Windchill:</td>")) + 9',0);
insert into macrodetail values ('GET WEATHER A',13,15,'[LOCAL3]',NULL,'posw( "[LOCAL1]", "</b>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',14,15,'[LOCAL3]',NULL,'mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',15,15,'[LOCAL4]',NULL,'"[LOCAL4]" + ", with a windchill of " + if( isnumber( "[LOCAL3]"), "[LOCAL3]", left( "[LOCAL3]", 2)) + ", "',0);
insert into macrodetail values ('GET WEATHER A',16,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", ''2px;">'', pos( "[LOCAL1]", "Humidity:</td>", [LOCAL2])) + 6',0);
insert into macrodetail values ('GET WEATHER A',17,15,'[LOCAL3]',NULL,'mid( "[LOCAL1]", [LOCAL2], 3)',0);
insert into macrodetail values ('GET WEATHER A',18,15,'[LOCAL4]',NULL,'"[LOCAL4]" + " and the humidity is " + if( isnumber( "[LOCAL3]"), "[LOCAL3]", left( "[LOCAL3]", 2)) + " percent. "',0);
insert into macrodetail values ('GET WEATHER A',19,36,'',NULL,'"[LOCAL4]"',0);
insert into macrodetail values ('GET WEATHER A',20,37,'',NULL,'',0);
insert into macrodetail values ('GET WEATHER A',21,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", ''width="100%"><b>'') + 16',0);
insert into macrodetail values ('GET WEATHER A',22,15,'[LOCAL3]',NULL,'posw( "[LOCAL1]", "</b>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',23,15,'[LOCAL4]',NULL,'"The forecast for " + mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2] ) + " is "',0);
insert into macrodetail values ('GET WEATHER A',24,15,'[LOCAL2]',NULL,'[LOCAL3] + 10',0);
insert into macrodetail values ('GET WEATHER A',25,15,'[LOCAL3]',NULL,'posw( "[LOCAL1]", "</td></tr>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',26,15,'[LOCAL4]',NULL,'"[LOCAL4]" + mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',27,15,'[LOCAL4]',NULL,'ph_replaceall( "[LOCAL4]", "...", ". " )',0);
insert into macrodetail values ('GET WEATHER A',28,15,'[LOCAL4]',NULL,'ph_replaceall( "[LOCAL4]", "</b>", "" )',0);
insert into macrodetail values ('GET WEATHER A',29,15,'[LOCAL4]',NULL,'ph_replaceall( "[LOCAL4]", "~r", "" )',1);
insert into macrodetail values ('GET WEATHER A',30,15,'[LOCAL4]',NULL,'ph_replaceall( "[LOCAL4]", "~n", "" )',1);
insert into macrodetail values ('GET WEATHER A',31,36,'',NULL,'"[LOCAL4]"',0);
insert into macrodetail values ('GET WEATHER A',32,16,'',NULL,'if( len ( "{WEATHER STR}" ) < 250, 999, 1)',0);
insert into macrodetail values ('GET WEATHER A',33,26,'',NULL,'"ERROR"',0);
insert into macrodetail values ('GET WEATHER A',34,10,'WEATHER STR',NULL,'"Problem getting forcast."',0);
|
|
|
Edited by TonyNo
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 24 2005 at 10:57 | IP Logged
|
|
|
TonyNo,
By replacing the ph_readfile .... code with the proper ph_geturl ... code it was no dice:
the server replies with a protocol-violation so I have made a workaround:
Code:
ph_saveurl ( "http://www.wunderground.com/cgi-bin/findweather/getForecast ?query=%20eindhoven", "getforecast.htm", 1 )
|
|
|
and then your original macro with the ph_readfile ... is been executed .... so first the whole page is been saved to my HD and then it is read.
Now I would like to store the values in a couple of GV's like temperature in Celsius (not fahrneheit), humidity and windspeed/direction so I can work with them further e.g. if I know the outside temp. and the inside temp. together with humidity I can change my Central Heating systems behaviour but that is for MUCH later...
here is a copy&paste from the eventlog:
first [LOCAL3] is being shown
then the rest:
Code:
The temperature is 39 degrees, with a windchill of 30, and the humidity is <a percent.
The forecast for Thursday is Chance of Rain. High: 44° F / 7° C Wind SW 15 mph / 25 km/h
|
|
|
the humidity is imported incorrect... but what I would like to know is what exactly [LOCAL3] contains....
Another thing: how can I store the temp. and the windchill as well as the forecast in a seperate GV?
Is that major surgery pertaining the code?
Peter
Edited by krommetje
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 24 2005 at 15:08 | IP Logged
|
|
|
The first Local3 user message was just for testing; it can be deleted.
Are you using the saved code or the current code, which may be different?
How many GV's do you want to use?
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 25 2005 at 00:46 | IP Logged
|
|
|
I am using the last code you posted that was tweaked to
work with the html supplied by me on my website.
I would like to have GV's for the Temperature, the windchill, humidity and the forecast... SO that would be 4 GV's in total... However the humididty is imported incorrect so this has to be solved first... I've been trying to get something out of the code and I see a lot of escape seq. and html-code but for the moment this is all yet to clear-up in my mind. I think I am going to print both and take them to my work, that way I can look at them while working.... this code is at this time above my knowledge of programming for PH....
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 25 2005 at 06:44 | IP Logged
|
|
|
Damn: sorry all.....
while adding an entry about writing the temperature into a GV my entire PH-server crashed.. First the FAT where damaged, after repairing these I lost Networking and the Mouse as well as several parts of the file-system that where damaged beyond repair.... PH was also damaged beyond repair...
Because I save a daily database backup on another disk, and after reinstalling windows and PH and putting back the Database all started running again (after a few hours of catching up past due events) For now it all runs again ...
Now:
I wanted to re-SQL the weathermacro into PH again but now I get a syntax-error... Since we are back to where we started.....
here's me showing off in another part of this forum about my server and its running time
Peter
Edited by krommetje
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 25 2005 at 07:09 | IP Logged
|
|
|
No! That is terrible! Sorry to hear about your troubles.
By code, I meant the HTML page on wunderground. The code I am seeing on my end has changed recently.
So, you import the macro above and get a syntax error?
I just noticed that I didn't change the last line, which assigns a value to WEATHER STR. Did you recreate this GV?
I'll delete this GV when I update for the four new ones.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 25 2005 at 07:46 | IP Logged
|
|
|
OK, here's the update. It now gets temps in C and assigns the individual values to LOCAL4-7 (temp, windchill, humidity, and forecast).
Note that this was made to work with the saved HTML you posted above.
Code:
insert into macroheader values ('GET WEATHER A','GET WEATHER',0,0,1);
insert into macrodetail values ('GET WEATHER A',1,15,'[LOCAL1]',NULL,'ph_readfile("getforecast.htm")',0);
insert into macrodetail values ('GET WEATHER A',2,37,'',NULL,'The next 3 lines delete carriage returns, newlines, and tabs',0);
insert into macrodetail values ('GET WEATHER A',3,15,'[LOCAL1]',NULL,'ph_replaceall( "[LOCAL1]", "~r", "" )',0);
insert into macrodetail values ('GET WEATHER A',4,15,'[LOCAL1]',NULL,'ph_replaceall( "[LOCAL1]", "~n", "" )',0);
insert into macrodetail values ('GET WEATHER A',5,15,'[LOCAL1]',NULL,'ph_replaceall( "[LOCAL1]", "~t", " " )',0);
insert into macrodetail values ('GET WEATHER A',6,37,'',NULL,'Find Temperature',0);
insert into macrodetail values ('GET WEATHER A',7,15,'[LOCAL2]',NULL,'posw( ''[LOCAL1]'', ''<div style="font-size: 17px;'')',0);
insert into macrodetail values ('GET WEATHER A',8,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", "</nobr>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',9,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", "<b>", [LOCAL2]) + 3',0);
insert into macrodetail values ('GET WEATHER A',10,15,'[LOCAL3]',NULL,'posw( "[LOCAL1]", "</b>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',11,15,'[LOCAL3]',NULL,'mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',12,15,'[LOCAL4]',NULL,'if( isnumber( "[LOCAL3]"), "[LOCAL3]", left( "[LOCAL3]", 2)) + "°C"',0);
insert into macrodetail values ('GET WEATHER A',13,36,'',NULL,'"[LOCAL4]"',0);
insert into macrodetail values ('GET WEATHER A',14,37,'',NULL,'Find Windchill',0);
insert into macrodetail values ('GET WEATHER A',15,16,'',NULL,'if( posw( "[LOCAL1]", "Windchill:") = 0, 5, 1)',0);
insert into macrodetail values ('GET WEATHER A',16,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", "</nobr>", posw( "[LOCAL1]", "Windchill:</td>"))',0);
insert into macrodetail values ('GET WEATHER A',17,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", "<nobr><b>", [LOCAL2]) + 9',0);
insert into macrodetail values ('GET WEATHER A',18,15,'[LOCAL3]',NULL,'posw( "[LOCAL1]", "</b>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',19,15,'[LOCAL3]',NULL,'mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',20,15,'[LOCAL5]',NULL,'if( isnumber( "[LOCAL3]"), "[LOCAL3]", left( "[LOCAL3]", 2)) + "°C"',0);
insert into macrodetail values ('GET WEATHER A',21,36,'',NULL,'"[LOCAL5]"',0);
insert into macrodetail values ('GET WEATHER A',22,37,'',NULL,'Find Humidity',0);
insert into macrodetail values ('GET WEATHER A',23,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", ''2px;">'', pos( "[LOCAL1]", "Humidity:</td>", [LOCAL2])) + 6',0);
insert into macrodetail values ('GET WEATHER A',24,15,'[LOCAL3]',NULL,'mid( "[LOCAL1]", [LOCAL2], 3)',0);
insert into macrodetail values ('GET WEATHER A',25,15,'[LOCAL6]',NULL,'if( isnumber( "[LOCAL3]"), "[LOCAL3]", left( "[LOCAL3]", 2)) + "%"',0);
insert into macrodetail values ('GET WEATHER A',26,36,'',NULL,'"[LOCAL6]"',0);
insert into macrodetail values ('GET WEATHER A',27,37,'',NULL,'Find Forecast',0);
insert into macrodetail values ('GET WEATHER A',28,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", ''width="100%"><b>'') + 16',0);
insert into macrodetail values ('GET WEATHER A',29,15,'[LOCAL3]',NULL,'posw( "[LOCAL1]", "</b>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',30,15,'[LOCAL7]',NULL,'"The forecast for " + mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2] ) + " is "',0);
insert into macrodetail values ('GET WEATHER A',31,15,'[LOCAL2]',NULL,'[LOCAL3] + 10',0);
insert into macrodetail values ('GET WEATHER A',32,15,'[LOCAL3]',NULL,'posw( "[LOCAL1]", "</td></tr>", [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',33,15,'[LOCAL7]',NULL,'"[LOCAL7]" + mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2])',0);
insert into macrodetail values ('GET WEATHER A',34,15,'[LOCAL7]',NULL,'ph_replaceall( "[LOCAL7]", "...", ". " )',0);
insert into macrodetail values ('GET WEATHER A',35,15,'[LOCAL7]',NULL,'ph_replaceall( "[LOCAL7]", "</b>", "" )',0);
insert into macrodetail values ('GET WEATHER A',36,36,'',NULL,'"[LOCAL7]"',0);
|
|
|
Edited by TonyNo
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 29 2005 at 09:55 | IP Logged
|
|
|
TonyNo,
the code imports OK and runs BUT the humidity is still />a
I've have added code to add the Temp, Windchill and humidty to its own GV and works so your tweaked code works...
Now explain the code to me please so I can learn something of it...
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 29 2005 at 14:16 | IP Logged
|
|
|
Good work! I will try to explain all of it tonight or tomorrow night.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 29 2005 at 23:41 | IP Logged
|
|
|
There are some comments in the macro. I'll discuss finding and pulling info from one section first.
A lot of this uses the posw function. This returns the postion in the string of what we are looking for.
After grabbing the whole HTML file, we first get the temperature.
Analysing the HTML, we need to find something near the temperature that does not show up anywhere else first. I chose '<div style="font-size: 17px;' to key off of. First, we'll get the position of this portion and load it into LOCAL2:
Code:
SET SYSTEM LOCAL2 posw( '[LOCAL1]', '<div style="font-size: 17px;') |
|
|
Then, we get closer by looking for "</nobr>" starting at the location previously found:
Code:
SET SYSTEM LOCAL2 posw( "[LOCAL1]", "</nobr>", [LOCAL2]) |
|
|
We can then get the position of the start of the temperature, which follows a "<b>"...
Code:
SET SYSTEM LOCAL2 posw( "[LOCAL1]", "<b>", [LOCAL2]) + 3 |
|
|
The temperature is terminated by a "</b>", so we find that, starting at the last found postion and put that into LOCAL3:
Code:
SET SYSTEM LOCAL3 posw( "[LOCAL1]", "</b>", [LOCAL2]) |
|
|
We can now pull the temperature value by grabbing LOCAL3-LOCAL2 characters (the length of the temperature), starting at LOCAL2:
Code:
SET SYSTEM LOCAL3 mid( "[LOCAL1]", [LOCAL2], [LOCAL3] - [LOCAL2]) |
|
|
I then check to make sure that the section grabbed is actually a number. If so, I do nothing. If not, I only grab the first two characters. I then append the "°C". This is then loaded into LOCAL4:
Code:
SET SYSTEM LOCAL4 if( isnumber( "[LOCAL3]"), "[LOCAL3]", left( "[LOCAL3]", 2)) + "°C" |
|
|
That's it for the temp!
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 30 2005 at 07:52 | IP Logged
|
|
|
TonyNo,
I took a look at the code and the following line which finds the humidity results to the famous [colour=red]![/colour]:
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 30 2005 at 08:10 | IP Logged
|
|
|
TonyNo,
I took a look at the code and the following line which finds the humidity results to the famous!
Code:
insert into macrodetail values ('GET WEATHER A',23,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", ''2px;">'', pos( "[LOCAL1]", "Humidity:</td>", [LOCAL2])) + 6',0);
|
|
|
At least in my system, this is the explanation why the humidity can't be found...
When I change the second pos( "[LOCAL1", to posw( "[LOCAL1", then the formula is verified OK but still no humidity is found. I have been playing around with the 6 at the end of the formula but always the result is a piece of HTML code...
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 30 2005 at 12:50 | IP Logged
|
|
|
Good catch! I'll take another look at it.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 30 2005 at 20:56 | IP Logged
|
|
|
OK! Change that line to:
Code:
posw( "[LOCAL1]", '#996;">', posw( "[LOCAL1]", "Humidity:</td>", [LOCAL2])) + 7 |
|
|
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: December 01 2005 at 08:13 | IP Logged
|
|
|
Hey TonyNo,
Changed and Working! the output is
Now I can make another formula which removes the </
Then I can make calculations with it....
Now.... You have been working hard for me , what can i do to return the favor?
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 01 2005 at 12:09 | IP Logged
|
|
|
Strange. I started using the actual page for your area and it worked last night. I'll check again, but they change things a lot there.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 01 2005 at 20:37 | IP Logged
|
|
|
Hmm. Works from here...
I just missed grabbing the temp, but the windchill, humidity, and forecast are shown.
|
Back to Top |
|
|
|
|