Information for Webmasters
Contents
» Introduction
» Flag Status
» Lighting Times
» Websites on the SRCF (incl. code examples.)
Introduction
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.
Flag Status
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
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.
Websites on the SRCF
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
Code Example
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.


