• Utility corner
BBCWeatherJ — a simple Java command-line utility to retrieve and dump
a BBC weather forecast feed
What is this?
BBCWeatherJ is a (very) simple command-line Java utility
that dumps a 3-day weather forecast or observation report
from the BBC Web site with
minimal (or no) formatting. It retrieves the information as
an RSS feed, parses the XML, and dumps the
weather information to the console.
it produces is lightly formatted (bold and underline) to make it
more human-readable, but this formatting can be turned off, so the
output can be fed into other scripts
BBCWeatherJ is the Java equivalent of the C-based utility
bbcweather, but this Java version
is more tolerant of the oddities of the BBC webserver.
BBCWeatherJ has the dubious distinction of being developed and built
on an Android device, using the Java command-line tools of the
KBOX project. Part of the purpose of
BBCWeatherJ is to serve as a proof-of-concept for Java development
Installation (on anything except Android/KBOX)
Assuming that you a Java runtime (version 6 or later) available,
installation consists of downloading the compiled Java JAR file and
copying it to any convenient directory. Then run it like this:
$ java -jar /path/to/bbcweatherj-0.0.1.jar [options]
On Linux, you can download the source code bundle, unpack it, and run
$ make install-linux
This will install a script that will allow the utility to be run as
Building (on anything except Android/KBOX)
Download the source code bundle, unpack it, and run
$ make clean all
You might need to edit
env.mak to indicate the path to
the Java compiler. This build will produce
Building on Android/KBO3
You need to be running the KBOX shell for this, and to have installed
java-support package — see here
for more details.
Download the source code bundle and copy it to the Android device.
Unpack it using
unzip (part of the KBOX base system).
Then, in the source directory, do
$ ANDROID=1 make clean all
You might need to edit
env_android.mak to indicate the path to
the Java compiler and
dx utility. This build will produce
bbcweatherj.dex in the
You can run the utility like this:
$ dalvikvm -cp deploy/bbcweatherj.dex net.kevinboone.bbcweatherj.CmdLine [options]
make install-android to install a script that
will provide the utility as
When run without command-line arguments,
a 3-day forecast for London, UK. The switch
current observations rather than a forecast.
For other locations, use the name of a city on the command line, or a
numerical location code.
To get a list of supported city names, use
So far as I know, the BBC does not publish a list of numeric location
codes. These code can be found by using the BBC Web site to get a forecast
for a specific location, and inspecting the URL used.
Only a small number of locations is built into BBCWeatherJ — most major
UK cities. To avoid the need to use numberical codes, the utility will
read location data from a user-specified file. Use the
switch to specify the file location. The file should have the following
Location names can contain spaces (escaped by a '\') and punctuation,
but bear in mind that
such names may be tricky to enter on the command line. Because of a limitation
in Java, the location names must be written using characters from the
ISO8859-1 character set (not UTF-8). So care has to be take with
non-Latin characters. There is a sample location data file in the source
$ bbcweather -o sheffield
BBC Weather - Observations for Sheffield, United Kingdom
Wednesday - 20:00 GMT: Clear Sky, 2°C (36°F)
Temperature: 2°C (36°F), Wind Direction: North Westerly, Wind Speed:
9mph, Humidity: 66%, Pressure: 1018mb, Rising, Visibility: Very Good
-w switch to set the console width if it is less
than 80 columns; BBCWeatherJ breaks long lines at spaces to fit the
Most obviously, the BBC could change the format of its weather feeds,
or the URL of the feed server, at any time. In either of these eventualities,
this utility will need to be modified.
The output formatting (bold, underline) is done by emitting ANSI control
codes to the terminal. This works with Linux and most real terminals, but
will fail in the Windows console (thanks, Microsoft). Use the
switch to turn off formatting altogether.
bbcweather is copyright (c)2012 Kevin Boone, distributed
according to the GNU Public Licence, version 2. In essence that means that
you may do whatever you like with the software, at your own risk, provided
that the original authorship remains clear. There is no warranty of
Compiled Java JAR file