Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-02-05 22:38:36

Leithen
Member
From: Scotland
Registered: 2006-02-05
Posts: 24

Include Weatherdata?

I’m very much a “user” considering using a CMS for the first time, so my apologies if this is a daft question – however…

I’m looking to create a site that includes weather data from a weather station – the station software includes an pc ftp client and the ability to create templates that will upload the latest data and images (graphs etc) to the server at whatever interval you specify. I’ve had the system running in a very amateurish way for nearly a year at www.crieffvechter.com using the templates included that generate static pages.

The template system will allow me to upload the data with any formatting around it and with any file extension.

How could I incorporate this data automatically into pages generated by textpattern? I’d like to have several pages dedicated to the weather data, but I’d also like the front page to show current temperature for example.

Many thanks for any help.

Offline

#2 2006-02-06 06:03:13

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

Re: Include Weatherdata?

Textpattern supports PHP, so until you get “down and dirty” with it, you could always create an article and include the page such as: < txp:php> @include(“staticpage.html”); </ txp:php>

See the PHP howto: http://textpattern.com/faq/34/how-do-i-use-php-code (I’d link prettier, but I can’t figure where to have punbb let me turn on BBCode..

Offline

#3 2006-02-06 10:53:39

Leithen
Member
From: Scotland
Registered: 2006-02-05
Posts: 24

Re: Include Weatherdata?

Thanks neptho, so I could make the weather station ftp software upload a php file containing the necessary data – it would update or overwrite itself every 15mins for example – and then I could make a php reference to that file from within my different textpattern pages.

I’m wanting to “insert” data, for example temperature figures, or wind speed, rather than load a whole page, so I presume I have to figure out how to identify individual snippets within the uploaded php file.

Probably PHP 101, but somewhat scary for me – many thanks though!

Offline

#4 2006-04-11 17:24:31

Leithen
Member
From: Scotland
Registered: 2006-02-05
Posts: 24

Re: Include Weatherdata?

I’ve managed to make this work as I originally wanted – not sure if it will be of any interest or use to others, but I’d thought it was worth “closing” the thread with the result. All credit has to go to Carter Lake who published the php method shown below.

I started by getting the weather station to output an html file with all the weather data seperated by the “|” character, and have it uploaded to a subdirectory of the textpattern dir. An excerpt looks like this;
<code>
13:43|0.5| 6:33|7.8|-4.5|11.8|-7.8|92
</code>

The Carter Lake php file “getraw.php” is also placed in the subdirectory of the textpattern dir;
<code>
function get_raw( $rawfile ) {
$rawdata = implode(‘’, file($rawfile));
$rawdata = explode(‘|’, $rawdata);
return $rawdata;
}
</code>

Then I placed the code as seen below on the page required, between the <code></head> and <body></code> tags;
<code>
<txp:php>
require_once txpath.’/weather/getraw.php’;
global $wxdata;
$wxdata = get_raw(txpath.’/weather/weatherdata.html’);
</txp:php>
</code>

All that remained was to create misc forms for each individual piece of data, referenced by their number in the array, that I wanted displayed. Here, for example is the form for Temperature called “temp”;
<code>
<txp:php>
global $wxdata;
echo “$wxdata11 &deg;C”;
</txp:php>
</code>

which allows me to use <code><txp:output_form form=“temp” /></code> to insert the reading in the page.

Along with some graph work using the subModal dialog display wonderment the results can be seen here

I’ve no doubt there is a quicker and simpler way, but for now I’m happy.

Last edited by Leithen (2006-05-07 15:44:59)

Offline

Board footer

Powered by FluxBB