Over the last couple of years while using Linux, I've slowly become better at what could loosely be described as "hacking".
Now DON'T PANIC! - don't get me wrong - I'm not some Linux guru who can cut perl code with my toes blindfolded...just somebody who sometimes at a very low level likes taking someone else's code & modifying it for my own needs. Sometimes I might even improve on the original! *cough*.
I mainly focus on stuff that is Palm related, mainly trying to integrate some of the command line tools available for Linux->Palm connectivity with some well known Linux applications.
Christchurch Bus Timetables for the Palm
One thing I've always wanted to have handy on my Palm is an app that keeps track of times for public transport in my city (Christchurch, NZ). Christhurch with a population of around 360,000 is to small to have a subway system, but over recent years with a Bus Exchange built, the bus system is actually very very good. Electric buses do loops around the CBD, & with the use of GPS systems installed on buses & their frequency it actually really is a viable solution to using the car, as I think more & more Cantabrians are realising.
Anyway while trawling the web recently I found an app called BusSched for the Palm. Its written by an Irishman for the Dublin bus system. Looking at the format of the Irish schedules, I realised they where very similar to the bus schedule times for Christchurch. The only problem was writing a script that did the hard work in writing out a BusSched compatible database. So I sat down to write a perl script that does just that!
Now its not perfect, & you do need todo some manual "massaging" of the data, but this script basically does all the hard work!
You need to set-up a config file for each route you need data for. For instance Route 24, Hyde park to Bromley, Weekday timetables config file looks like this (24_mon_fri1.txt). The format of the file is explained thus:
@MON_FRI_INCR = (2);
$MON_FRI_URL = "http://rtt.metroinfo.org.nz/rtt/public/Schedule.aspx cont ...
@MON_FRI_HEAD = (H,A,BHS,U,D,B,L,F,E,W);
@MON_FRI_INCR : The number of rows you see after the words "Then at these minutes past the hour between xx and xx". In the case there are 2 rows. If you have multiple occurances of this happening, you simply add the number of shown in the next occurance (say 3 rows) - this would look like this "@MON_FRI_INCR = (2,3);"
$MON_FRI_URL : The URL you want to grab from MetroInfo. Note: You need to grab the inline frame.
@MON_FRI_HEAD : A one or two letter character to define the column. In this example the "H" refers to "Hyde Park".
If you see the timetables for Route 24 you see you would need 6 such config files (for the weekday, saturday, sunday routes each way). In bus.pl you need to put the path to these config files here:
do "/path_to_config_files/$config.txt"
Running this command would then output to the command line the converted "row" of data needed for the BusSched compatible database.
./bus.pl 24_mon_fri1
You'd run this script for all the config files needed for the route. Now its time to start building up the BusSched compatible database! Here is the text file that creates the database I have built up for myself. You basically take each output of the script & build up a row of data for each route in this format:
24
Hyde Park
Bromley
data for Weekday 1
data for Weekday 2
data for Saturday 1
data for Saturday 2
data for Sunday 1
data for Sunday 2
H: to/from Hyde Park|A: to/from Avonhead M|U: to/from Canty Uni| cont ..
The headings after the data should match up with the headings given in the config files. You'll need todo some manual massaging of the data (removing multiple commas etc etc but nothing major). Once you have built up all the routes you need, you run this command (you need to compile pdbmake for Linux):
pdbmake -a -c DCBS -t DATA -n "Christchurch Bus Timetables" chchbus.txt
This produces "chchbus.pdb" which can be installed for viewing on your Palm! I know all of this sounds awfully complicated, but the best way to figure it out & get it working is too try for yourself. Here is a zip file with all the config files I currently have for myself (in the "buses" directory), "chchbus.txt" as well as the resulting "chchbus.pdb" & "pdbmake".
If you want me to add your own Route to the database, contact me.
You need the following perl modules installed (CGI optional): CGI qw(:standard), LWP::Simple qw/get/, HTML::Parser, HTML::Element & URI::URL to use bus.pl. Remember to make the script executable (chmod +x) & perhaps rename the download to "bus.pl".
Good luck!
| Back |
Thats all folks at the moment! If I come up with anything else I'II post it here.