cloudy

Author Topic: PHP Extraction of WD Avg/Ext HTM Files  (Read 43056 times)

0 Members and 1 Guest are viewing this topic.

Offline lulu836

  • Linda
  • Posts: 2,232
  • Louisiana
    • Luv Retirement
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #30 on: December 24, 2007, 03:10:38 PM »
Kevin,

I think what's confusing all of us "PHP still in it's learning stages" people is that in the original script you've got the following code:
Code: [Select]
############################################################################

## THINGS TO CHANGE
// What website contains the data
$website = "http://www.hebrides-photos.com/weather/";

// Which Datafile to look at
$datafile = "December2007.htm";

# END OF CHANGES
#############################################################################

This points to a specific month/year file, that's why I was asking if you needed 12 avgextract.php files for each year.
How do you code it to call all the months of a year using this php file with the form code you put above? Also, where does that form code go, is it in the main page (Sample.php) or the avgextract.php file?

Sorry for the questions, it's just that PHP still confuses the hell out me. I really should sit down and go through a PHP tutoral at some point.  :wink:

Yeah...^^^^^^^^^^^^^^


Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #31 on: December 24, 2007, 04:06:47 PM »
Change the code section that looks like:

Code: [Select]
#####################################################################

## THINGS TO CHANGE
// What website contains the data
$website = "http://www.hebrides-photos.com/weather/";

// Which Datafile to look at
$datafile = "December2007.htm";

# END OF CHANGES
######################################################################

To the code below....

Code: [Select]
#####################################################################

## THINGS TO CHANGE
// What website contains the data
$website = "http://www.hebrides-photos.com/weather/";

// Which Datafile to look at
//$datafile = "December2007.htm";
// Get $datafile from below...

$mnthname = array('January', 'February', 'March', 'April', 'May', 'June',
    'July', 'August', 'September', 'October', 'November', 'December');
   
$datefile = "";

if ( isset($_GET['date'] ) && strlen($_GET['date'] ) == 6) {
        $mon = intval( substr($_GET['date'],4,2) );
        if ($mon > 0 && $mon < 13 ) {
                $datafile = $mnthname[ $mon - 1 ] . substr($_GET['date'],0,4) . ".htm";
        }
}

if ( strlen($datafile)  == 0) {
        $datafile = date("FY") . ".htm" ;
}

# END OF CHANGES
######################################################################

In the HTML portion of the page (near the top) place the form:

Code: [Select]
Select a Different Report:
<form  method="get" action="avgextract.php" >
    <select name="date">
        <option value="200709"> September 2007 </option>
        <option value="200710"> October 2007 </option>
        <option value="200711"> November 2007 </option>
        <option value="200712"> December 2007 </option>
    </select>
    <input type="submit" value="Go" />
</form>


What does it do...

o It changes the script to look for a variable sent to it via a form input.

o First it looks to see if there was any variable received and if it is exactly 6 characters long (the data string).

o If it is, it uses that to set the datafile name.  It figures out the Month name to use from the month part of the date string it got.

o If not, it uses the current date and year to set the datafile to the current month/year.

o The form section allows the user to input which month/year they want to view.  You would need
to include each year/month you have or change the script to look for which files are there.

Now you have a wrapper around the script.  It no longer is fixed to a specific date, the user can change the report to what you allow.

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline Budgie

  • Martin
  • Global Moderator
  • Posts: 4,635
  • WML Station: WD00934 CWOP: CW7959
  • Isle of Lewis, Scotland
    • Hebrides-Weather
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #32 on: December 24, 2007, 04:18:22 PM »
You, Sir, are a Gent and may all your Christmas presents be the toys you've always wanted.  :D =D&gt;

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #33 on: December 24, 2007, 06:18:41 PM »

Added to my website now that I have a months worth of data...

http://www.tnetweather.com/tws-dailynoaa.php

there is not month selector because there is only one month... Jan 1st, it will show a selector for Dec2007 and Jan2008

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline jhobby

  • Posts: 76
  • Silver Cliff, Colorado, USA
    • Silver Cliff, Colorado Weather
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #34 on: December 24, 2007, 06:52:44 PM »
Kevin, Yes Thanks alot for the extra info., I did not what to ask where to put the form - date script after you gave me the color of form info and I put the date script everywhere you could think of and still didn't get it.

Thanks again and have a Merry Christmas. -Jeff

Offline jwwd

  • Posts: 3,545
  • Silkeborg, Denmark (56:10:58 N-09:30:26 E) - Elevation 75,35 meters
    • Weather at Silkeborg, Denmark
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #35 on: December 24, 2007, 09:43:42 PM »
Hi Kevin

Thanks for the improvement - its very cool.

I just saw, that the links to the graphs are not changing - when I choos a different month.

Merry christmas to you - here in Denmark we just finished celebrating the christmas..............eaten too much................again.

Best regards,

Henrik

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #36 on: December 25, 2007, 03:55:53 AM »
World time is sometimes a bit strange... it is only 9:52pm Xmas Eve here right now.... Wife's Bday party is over and I managed not to eat too much.  Santa won't be here for many hours still ...

I noticed that issue about the chart URL's earlier this afternoon but didn't have time to look at it other than to say.... ops.. forgot about that.

The issue is/was that the original script had the URL hard linked to the year month.

                    echo '  <a href="' . $website . '200712' . $day . '.gif">
                        Click Here for 24 hour Chart of this day</a><br/> <br/>' . "\n";


I had originally planned on going back and changing that but forgot about it.

I've changed the script that I am using to do this instead...

                    echo '  <a href="' . $website . $yearnum . $monthnum . $day . '.gif">
                        Click Here for 24 hour Chart of this day</a><br/> <br/>' . "\n";


Which turned out to be harder than I thought it should be as that section of code isn't given the date in that format, just as the filename itself like December2007.htm  so I had to do some more than cute programming to get what I wanted.

I need to go back and redo that section to make a better fix.

I will be updating the script in the scripts area soon to add the code for checking for date and changing this value as well...

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline jwwd

  • Posts: 3,545
  • Silkeborg, Denmark (56:10:58 N-09:30:26 E) - Elevation 75,35 meters
    • Weather at Silkeborg, Denmark
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #37 on: December 25, 2007, 06:48:28 AM »
Hi Kevin

Thanks for your quick reply. I hoped your wife had a great birthday.

Today we relax here in Denmark and wait for a lot of x-mas lunch´es the next days.................more food.

Do you think it would be possible to change the form to be static? Im not sure how I should explain it - but on my pages I have links for each month which links to my months files - see this link:

www.buskelundtoften.dk/vejret/english/rapporter.php (look for "Year- and month data")

Best regards,

Henrik

Ps. say hi so santa and tell him that I liked all my presents.  :D


Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #38 on: December 25, 2007, 03:08:38 PM »
Merry Christmas Henrik,

Still waiting for the family to show up.... its now 9am...  presents under the tree and the traditional family breakfast is cooking...


As for the static part, you can make it do anything you want.  I personally prefer dynamic pages as one page can do what many can, but its up to you.

This would make more sense to me....

<tr>
    <td width="76"><a href="../vejrdata/rapport.php?year=2007">2007</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200701">Jan</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200702">Feb</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200703">Mar</a></td>

    <td><a href="../vejrdata/monthdaily.php?month=200704">Apr</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200705">May</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200706">Jun</a></td>

    <td><a href="../vejrdata/monthdaily.php?month=200707">Jul</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200708">Aug</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200709">Sep</a></td>

    <td><a href="../vejrdata/monthdaily.php?month=200710">Oct</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200711">Nov</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200712">Dec</a></td>
</tr>


Note that only two scripts are used for the entire year and month daily reports.
« Last Edit: December 25, 2007, 03:22:18 PM by TNETWeather »

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline lulu836

  • Linda
  • Posts: 2,232
  • Louisiana
    • Luv Retirement
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #39 on: December 25, 2007, 05:59:11 PM »
I'm seeing all these comments:  Yeah got it working.  Thumbs up-works for me etc., and that's just not true.  All of us can exhibit one "pretty page" but when you call a different month there sits the bare-faced (but highly improved) daily report.  Someone enlighten me if I'm wrong but we still need to either use the css on each resulting page to "make it pretty" and save that page renamed to something like janext.php. or use an external css and call it to a new page.   We can then either include each page in a menu dropdown OR make another dropdown box that points to the pretty page.  IOW the extractor is just a means to an end.  Right?

Understand that I'm very grateful for the script and all the help from you Kevin but I'm just trying to sort out what the next obvious step is for me.  I already have a "pretty" January page and February page.....I just need to know if I'm on the right track.
« Last Edit: December 25, 2007, 06:07:04 PM by lulu836 »


Offline weatherc

  • Posts: 1,636
  • Salo, Finland
    • Weatherstation Salo,FI
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #40 on: December 25, 2007, 06:10:31 PM »
Hi and Merry Christmas from Finland!

I played a bit with this great script and get get it working fine, but I found the Max and Min of pressure are missing in the list even if they are are in list:
Code: [Select]
$parts = array(
        array("Raintotals",0),
        array(". on day",0),
        array("Average ",3),
        array("Rainfall for month",4),
        array("Rainfall for year ",4),
        array("Maximum rain per minute",5),
        array("Maximum temp",3),
        array("Minimum temp",3),
        array("Maximum pressure"),
        array("Minimum pressure",3),
        array("Maximum windspeed",3),
        array("Maximum gust",4),
        array("Rain for the day",4),
        array("Minimum humi",3),
        array("Maximum humi",3),
    );

Is there any way to get the daily rain (what not show on every day) there too?  #-o :reindeer:

Henkka

Offline jwwd

  • Posts: 3,545
  • Silkeborg, Denmark (56:10:58 N-09:30:26 E) - Elevation 75,35 meters
    • Weather at Silkeborg, Denmark
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #41 on: December 25, 2007, 07:02:05 PM »
Merry Christmas Henrik,

Still waiting for the family to show up.... its now 9am...  presents under the tree and the traditional family breakfast is cooking...


As for the static part, you can make it do anything you want.  I personally prefer dynamic pages as one page can do what many can, but its up to you.

This would make more sense to me....

<tr>
    <td width="76"><a href="../vejrdata/rapport.php?year=2007">2007</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200701">Jan</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200702">Feb</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200703">Mar</a></td>

    <td><a href="../vejrdata/monthdaily.php?month=200704">Apr</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200705">May</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200706">Jun</a></td>

    <td><a href="../vejrdata/monthdaily.php?month=200707">Jul</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200708">Aug</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200709">Sep</a></td>

    <td><a href="../vejrdata/monthdaily.php?month=200710">Oct</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200711">Nov</a></td>
    <td><a href="../vejrdata/monthdaily.php?month=200712">Dec</a></td>
</tr>


Note that only two scripts are used for the entire year and month daily reports.

Hi Kevin

Thanks for your reply.

The reason why I use a static "calendar" is that some of my montly reports are different from eachother and they seems to be "messed up" by the avgextract.php scripts. (But from September 2007 and forward its working fine)

See this: http://www.buskelundtoften.dk/vejret/sample.php

How does the monthdaily.php look like?

Have a very pleasant christmas with your family.

Best regards,

Henrik

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #42 on: December 25, 2007, 07:31:00 PM »
Hi and Merry Christmas from Finland!

I played a bit with this great script and get get it working fine, but I found the Max and Min of pressure are missing in the list even if they are are in list:

The script is skipping it because those lines have "in. on day" in them (thinks it is rain data).  Working on a fix.

Quote
Is there any way to get the daily rain (what not show on every day) there too?

Not easily the way the script was written.  In the tables that I tested when I wrote it, none of them had rain show up like that in them even when they had rain that day.

The issue is that since it is not always there, it is not easy for the script to know when the table has ended.  I will be looking at it later to see if there is an easy fix.

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline bdtripps

  • Posts: 69
  • Youngtown, AZ
    • Agua Fria Ranch Youngtown, AZ
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #43 on: December 25, 2007, 07:37:33 PM »
Hi Kevin,

Merry Christmas, Great script. I have it working but get this  Notice: Undefined variable: datafile in C:\usr\local\Apache2\htdocs\webfiles\avgextract.php on line 113 until I click on the go button for a month. Click here to check it out. http://aztripamer.net/webfiles/wx21.php Any help would be appreciated at this time.

Thanks,

Bill Trip
« Last Edit: December 25, 2007, 09:30:23 PM by bdtripps »
B.Trip
Arizona
DavisVP2 w/ FARS, Weather Envoy Wireless
Internet connection cable
Win7, Intel Core i7 920, 9GB Ram,

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,859
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: PHP Extraction of WD Avg/Ext HTM Files
« Reply #44 on: December 25, 2007, 07:41:44 PM »
Hi Kevin

Thanks for your reply.

The reason why I use a static "calendar" is that some of my montly reports are different from eachother and they seems to be "messed up" by the avgextract.php scripts. (But from September 2007 and forward its working fine)

That is most likely due to a format change in how those files were created.  In which case, extract script won't work.  If there is a format change in the future, it might be the same as well.

This is after all parsing an HTML file and what the format of that file is effects what it sees.  The same thing goes for NOAA Forecasts etc...

Quote
How does the monthdaily.php look like?

Mine looks like (I called it dailynoaa but monthdaily makes more sense and I used date as the variable not month...

http://www.tnetweather.com/tws-dailynoaa.php?date=200711

It uses an external CSS style sheet to get its Style from:

http://www.tnetweather.com/t/tws-dailynoaa.css

I have not written a new sample for it though yet.

All you need is Time, Aptitude and Desire ... and you can build just about anything...

 

cumulus