A site on the World Wide Reb

The World Wide Reb is the tongue-in-cheek name given to the network of distributed REBOL applications accessible from the REBOL/View desktop - more formally it is known as the REBOL Distributed Desktop. Once you’ve setup a rebsite you can add it to distributed desktop and make it available to all REBOL/View users.

The REBOL folks reckon that setting up a rebsite is easier than setting up an ordinary HTML web page. Let’s put that claim to the test.

A REBOL mini-application for the Internet

Because users browse the World Wide Reb using their REBOL/View desktop, we’ll need some sort of Internet-enabled application. The file renamer we developed in the previous articles is not really suitable as it is only intended for use on the local machine. Also REBOL has built-in security that stops its own programs from accessing the user’s computer without permission. I don’t want my rebsite asking visitors for access to files on their computers - I certainly wouldn’t like that!

No, it has to be a network-oriented application that doesn’t need access to files on the user’s computer.

The “Melbourne Weather” Application

I recently had the dubious privilege of working in a basement level office that lacked any natural light let alone a window. Before leaving the office we always wanted to know what conditions were like up on the surface. Rather than climbing the stairs to the nearest window we would hit the Bureau of Meteorology web site and check the latest observations at http://www.bom.gov.au/products/IDV65119.shtml.

Sample output from the BoM web site.

Figure 1

The trouble with this web page is that it shows data from a heap of observation stations but all I wanted was Melbourne. It also includes more observations than I needed - two measures of wind speed? And what is a dew point, anyway? Information overload! What I need is a little program that will access this page and tell me the temperature, whether it’s windy out and if it’s been raining.

Digression: So what IS the dew point?

“This is a measure of the moisture content of the air and is the temperature to which air must be cooled in order for dew to form. The dew-point is†generally derived theoretically from dry and wet-bulb temperatures, with a correction for the site’s elevation.

If the dry-bulb temperature is the same as the dew-point, the air is said to†be saturated and the relative humidity is 100%.”



“The temperature at which air becomes saturated and produces dew.”


There are countless approaches this task, and a REBOL solution is shown here:

Sample output of the Melbourne Weather Update program.

Figure 2

This will be the mini-application to include on the rebsite.

The program (Listing 1) addresses the two parts to the problem - extracting the required data and presenting the information in an easy-to-read form.

Parsing the web page

First we read the web page into the variable page. Then use the REBOL parse command to extract the data. Just as the layout command uses a dialect (the Visual Interface Dialect), the parse command also uses a dialect but this one is for text-processing rather than visual display. The format of the parse command is:

parse some_text [using these rules]

So the parse dialect allows us to build up a set of text-processing rules, as follows:

parse page [
    thru "Last updated: "
    copy data_item to "^/"
      (append data_list data_item)
    thru "Melbourne</a></td>" 
    thru <td nowrap align="center"> 
    copy data_item to </td>
      (append data_list data_item) 
    10 [thru <td align="center">
    copy data_item to </td>
      (append data_list data_item)

Or rephrased in English:

  • parse the HTML text stored in the page variable
  • move through the HTML until you find the text “Last updated: ”
  • copy everything from here until the end of the line into the variable data_item
  • append the contents of data_item to the empty list data_list
  • move through the HTML until you find the text “Melbourne”
  • move through the HTML until you find the tag
  • copy everything up to the tag and append it to the list data_list
  • repeat the following ten times: ** move through the list until you find the tag ** copy everything up to the tag and append it to the list data_list

The result is that the variable data_list holds a list that includes a date stamp and all of the current observational data for Melbourne (time of observation, temperature, dew point, relative humidity, wind direction, wind speed (km/h and knots), wind gust (km/h and knots), air pressure, rainfall since 9am) - a total of 12 fields. We now have our observations - time to present them in a graphical user interface (GUI).

But first…

A quick word about the REBOL path syntax. There are two ways to access each data element in a block such as data_list. One is to use the ordinals first data_list, second data_list, third data_list, and so on. But the method used here is the REBOL path syntax: data_list/1, data_list/2, data_list/3 - a bit like arrays in other languages.

A GUI display

Looking at the second part of Listing 1, we are familiar with the view layout command combination from the previous article. Next we introduce a backdrop effect - in this case a colour gradient starting as black (0.0.0) in the top left corner to a dark green (0.128.128) at the bottom right. The banner command gives the window a nice big title.

The next line is a doozy - and all it does is make a subheading in the format: “Monday 12 May 2003 at 18:00″! Let’s take it apart:

  • data_list/1 returns the first item in data_list, which is text in the format “18:12 AEST Monday 12 May 2003″ but all I need is the “Monday 12 May 2003″ part
  • parse data_list/1 none - using parse without any text rules (none) breaks the string at each whitespace to make the block: [”18:12″ “AEST” “Monday” “12″ “May” “2003″]
  • skip…2 takes the result of the parse function and skips the first two elements, resulting in the block: [”Monday” “12″ “May” “2003″]
  • parse data_list/2 none parses the second element of data_list (the observation timestamp), a string of the format “12 18:00″ into the block [”12″ “18:00″]
  • second selects the second string out of [”12″ “18:00″], and returns “18:00″
  • reform after the above processing, reform gets passed a block like this [[”Monday” “12″ “May” “2003″] “at” “18:00″], which it reduces and forms into the string “Monday 12 May 2003 at 18:00″
  • vh1 is a level 1 heading for video display

Phew! Sit down and have a Bex if you need to. It gets easier from here.

The pad command adds some space (60 pixels at the left and 20 pixels at the top) for the widgets that follow.

The next line uses the rejoin command to link up everything in the block and pass it as a string to vtext, which is a text field for video display. (Note: #”^(B0)” is the hexadecimal character code for the degree symbol.) And return moves the insertion point back to the left margin set by guide. This pattern repeats until we set a new margin and put in the “Done” button.

Save the code in Listing 1 to file melb_weather.r and we have an application that we can run from our own machine (run rebol melb_weather.r or double-click the melb_weather.r) or via the Internet as outlined below.

Setup a rebsite

Remember, this is the easy bit!

It should not come as a surprise that you setup a rebsite using a REBOL script and Listing 2 has mine.

The key points to note are:

  • the REBOL header must include the type declaration as shown
  • two tones are allowed for text-color the first (255.255.255) makes my icon labels white, the second (128.128.128) makes labels turn grey when the mouse rolls over the icon
  • and backdrop uses the same effect as in melb_weather.r
  • the file command adds our weather reporting application to the page

And that’s all there is to it - other files and “folders” are added in a similar way. The code in Listing 2 is saved as index.r and uploaded to a public web server along with melb_weather.r. To access the rebsite choose Goto on the REBOL/View desktop and enter the URL (e.g. http://member.melbpc.org.au/~tgosbell/rebsite/index.r) into the text field and click Goto.

Entering the URL in the REBOL/View desktop.

Figure 3

Maybe the REBOL folks are right - it does seem easy.

REBOL resources on the web

First published: PC Update Aug 2003 (online version updated)