21/12 | 22/12 | ||
---|---|---|---|
07:33 | 07:34 | ||
16:15 | 16:16 |
» Introduction
» Flag Status
» Lighting Times
» Websites on the SRCF (incl. code examples.)
» Drupal
The following information is aimed at College club webmasters who want to incorporate CUCBC data into their site. This page defines how CUCBC make this data available and includes a limited set of examples (using PHP) showing how to deploy this information to other sites. In general CUCBC cannot help individual webmasters/clubs with setting up such systems unless there is a technical problem with data provided by CUCBC.
You can access the current flag status from one of two files:
» http://www.cucbc.org/flag.txt
» http://www.cucbc.org/flag.xml
These files give the current flag status as a three letter code:
Code | Status | Notes |
---|---|---|
nop | Not Operational | Used during vacations. |
grn | Green | |
yel | Yellow | |
ryl | Red/Yellow | |
red | Red | |
blu | Cambridge Blue | |
gdb | GDBO |
Lighting times for today and tomorrow can be accessed from one of two files:
» http://www.cucbc.org/darkness.txt
» http://www.cucbc.org/darkness.xml
Line | Data | Format |
---|---|---|
1 | Date | YYYY-MM-DD |
2 | Lighting Down Today | HH:MM (24 hr) |
3 | Lighting Up Today | HH:MM (24 hr) |
4 | Lighting Down Tomorrow | HH:MM (24 hr) |
5 | Lighting Up Tomorrow | HH:MM (24 hr) |
The scheme for the XML file is self explanatory from element/attribute names.
Long term lightings data is available in XML and CSV format:
» XML Data for 2008
» CSV Data for 2008
The data is formatted as follows:
Column | Name | Format |
---|---|---|
1 | Date | YYYYMMDD |
2 | Lighting Down (Timestamp) | UNIX Timestamp |
3 | Lighting Up (Timestamp) | UNIX Timestamp |
4 | Lighting Down (Friendly) | HH:MM |
5 | Lighting Up (Friendly) | HH:MM |
The PHP date() function can be used to format the timestamp values in whatever date/time format is required. The "friendly" values give 24-hour clock times for lighting down and up.
NB: The date_sunrise() and date_sunset() functions available in PHP 5 will only generate approximations to CUCBC Lighting Times.
The SRCF does not allow PHP to access external files so we have made the four files listed above available locally on the SRCF machine.
The SRCF copies of these files are updated automatically every 4 minutes.
The absolute paths to these files are as follows:
\societies\rowing\river_status\flag.txt
\societies\rowing\river_status\flag.xml
\societies\rowing\river_status\darkness.txt
\societies\rowing\river_status\darkness.xml
This snippet exemplifies how SRCF hosted websites can retrieve the flag status-code using PHP:
<?php
$filename = '/societies/rowing/river_status/flag.txt';
// Only works on the SRCF.
// Gets data that is, at most, 4 minutes old.
$fp = fopen($filename, 'r');
$flag = fread($fp, filesize());
fclose();
// $flag now contains the three-letter flag status code.
?>
A suitable set of if...else blocks or a switch can now be used to produce relevant HTML based on the flag status.
The example below uses a switch block:
<?php
switch ($flag) {
case 'grn':
// Print HTML code to display green flag image/message.
break;
case 'yel':
// Print HTML code to display yellow flag image/message.
break;
...
default:
// Print HTML code to display 'flag status unavailable' message.
}
?>
Disclaimer: CUCBC provides the above examples "as is" and cannot guarantee their accuracy, effectiveness, security or operation. Please see the PHP Manual for more detailed PHP documentation.
A Drupal module is available that will provide a block displaying the current flag status along with today and tomorrow's lighting times. The data are obtained from the text files on the CUCBC web server (see above).
» CUCBC River Status Drupal Module
To install, extract the archive to your Drupal install's modules directory then move the [modules]/riverstatus/flag directory to /img/flag in your document root. The module will work with Drupal 5.x and 6.x.
© 2001 - 2024 Cambridge University Combined Boat Clubs. All rights reserved.