Posts tagged ‘caltrain’

Updated Caltrain Schedules

Caltrain sneaked in minor schedule updates on January 1. I confirmed my CaltrainPy still scrapes the HTML table properly, and did a 0.4.1 release. CaltrainPy can act both as a schedule application (it uses Tkinter for UI), or you can use it as a library to parse the HTML timetable into machine-friendly formats.

I also updated my online Caltrain schedules for Windows Mobile, iPhone and other small devices service.

Using Fabric to Deploy CaltrainJS

I wrote earlier about different options to deploy applications using Python, and one of the simplest tools is Fabric. While Fabric might not be enough for my work projects, it worked great on my Caltrain schedules application.

My project is really simple, but once I started looking at running Javascript compression and checking tools I realized I needed to add some automation to the process. I considered three options: Makefiles, SCons and Fabric. In the end I chose Fabric because I didn’t need to do much in the build steps, but I needed a quick and painless way to upload my changes to a staging site for tests. I think Fabric handles the last step best.

My build step is mostly copying files around. I have two Javascript files, one of which is produced by CaltrainPy. The format is pretty compressed already, so I just run sed on it to shorten AM to A, PM to P and take out – from certain fields. Previously I was doing this in the online application, but it makes sense to do this in the build step. I run the ShrinkSafe Javascript compression tool from the dojo project for the second file and combine the two scripts into a single file. I find it somewhat odd that a Javascript compression tool uses Java, but whatever works… The last mildly interesting part is the generation of a sitemap XML file, for which I just wrote a simple Python function. In the Fabric build step this becomes:

def build():
    "Build locally"
    # schedule.js is already compact, just minor tweak
    local("""sed -e 's/ AM"/ A"/g' -e 's/ PM"/ P"/g' -e 's/"-"/""/g' schedule.js >../stage/caltrain.js""")
    # our main script has a lot to compress
    local('java -jar custom_rhino.jar -w -fatal-warnings -c caltrain.js >>../stage/caltrain.js')
    sitemap()

Deploying to staging is even simpler:

def stage():
    "Deploy into staging environment on server"
    put('../stage/index.html', 'staging/path/on/server/index.html')
   ...

The one gotcha I run into with staging is that current version of Fabric does not seem to support wildcards. I first tried to put('*.html', '/path/on/server/') but that wouldn’t work. It seems like such a basic feature that I wouldn’t be surprised if it will be included soon.

For CSS compression I just used cleancss manually. I also looked at cssoptimizer but it was a bit too extreme to my taste. cleancss is based on csstidy so I could possibly integrate that into my build.

For validation I have used W3C validators, but it would be nice to be able to integrate validators in the build step as well. For Javascript it seems JSLint would be a good option. I haven’t spent any time thinking about HTML and CSS validation during the build step, but obviously this would be a nice thing to have as well.

Updated Online Caltrain Schedule Application

I spent a bit of time over the weekend and the last couple of days to refine my online Caltrain schedule application for Windows Mobile, iPhone and others. Earlier I had split the sources off from CaltrainPy, and now it was time to do some maintenance on the online version.

The new feature is the system map. I also realized that I can expand on this work to add support for fares and maybe other similar enhancements in the future. One of the major obstacles holding me back was that I wasn’t sure how to fit this in the very small amount of real estate I had available. I solved this by making the Trains header into a button like the direction and day of travel at the top of the application.

All I can say is that it is really frustrating trying to write Javascript for Windows Mobile. I was able to get the map to display without recreating the whole schedule, but at the price of leaving some clutter after the map (although some could consider the end result a feature). I also found a bug where the scrollbars appear when viewing in vertical mode although they shouldn’t. They go away when you switch to landscape and then back. This bug affects only Windows Mobile devices as far as I know. I also added a documentation page to help users figure out how to use the thing and what all the different symbols mean in the schedules.

The stylesheet and Javascript are now in their own files.

The final piece of work I did was ensure the HTML and CSS passed validation.

Caltrain Schedule Application Screenshot

Caltrain Schedule Application Screenshot

CaltrainJS in iPhone

The major problem my CaltrainJS application had with iPhone was that the page stretched too big and the iPhone browser zoomed so much it was impossible to read any text or operate the controls without continually zooming in and out. After checking some other pages optimized for the iPhone I noticed there was a meta tag I had not seen before. Doing some searches I finally found the Apple page that describes how to set the viewport so that iPhone displays the page in a more mobile friendly way. Now my application works in iPhone too.

More Work on Python and Javascript Caltrain Schedules

I finally decided to sit down and fix some annoyances in my Caltrain schedule applications written in Python and Javascript. I added the ability to filter trains that don’t stop at either your departure or destination stations. For the Python version I also added the ability to install the package simply with easy_install caltrain. Even nicer, when you have setuptools installed (as you do when using easy_install), the installer will place a script named caltrain in your $PATH, which makes it a snap to launch the application. The magic part in setup.py for the script is simply:

    setup_args["entry_points"] = {
        "gui_scripts": [
            "caltrain = caltrain:gui",
        ]
    }

where the line "caltrain = caltrain:gui" means that the script will be named caltrain, and it will call the calltrain.gui function (caltrain is the module).

I also finally made a proper page describing the project. Much nicer than needing to find the last post on this blog about the topic.

I noticed Caltrain has a page listing mobile applications. I wonder what it would take to get them to include my little apps there. I quite prefer the UI in my applications to all the others (except for the PalmOS version). This is what the latest Javascript version looks like:

Online Caltrain Schedule Application for Windows Mobile in Javascript

Online Caltrain Schedule Application for Windows Mobile in Javascript

Caltrain Schedule Feeds Available

Great news for Caltrain commuters since developers now have easier access to the Caltrain schedules in Google Transit Feed Specification (GTFS) format, which should result in better applications.

The feed itself is available here, and the developer license is short and sweet.

I hear we can thank Elliott Schwartz (maybe this guy?) for requesting the feed from Caltrain in the first place. I believe the people at the recent TransitCampBayArea are to thank for this service. Unfortunately I missed the event.

There is some Python code available to handle the feeds at Google Code.

CaltrainPy/JS 0.3

I released a new version of CaltrainPy and CaltrainJS yesterday. Caltrain changed schedules on March 3, 2008 and these releases incorporate the new schedule information. Incidentally, I found two errors in the official Caltrain online timetables, and this release fixes those as well. The issues are:

  1. Train 146 (weekday southbound) from Menlo Park to Santa Clara has times 13:XX (should be 1:XX).
  2. Train 195 (weekday northbound) arrives in San Francisco at 10:01 (should be 11:01).

This change also fixes the AM/PM bugs in the previous releases. The algorithm to determine AM/PMness of entries is much clearer now (and correct!).

You can download the package from Cheeseshop. To install, you must do: python setup.py install. easy_install does not work. I have also updated http://caltrain.heikkitoivonen.net/.

If you want to stay notified of updates for this software, I recommend you subscribe to the CaltrainPy Freshmeat project page.

Update: I forgot to mention that I contacted Caltrain about the schedule errors. Train 195 is already fixed, and they also acknowledged the errors with train 146, so that will probably get fixed soon.

CaltrainJS 0.2 – Caltrain Schedule

After I had released CaltrainPy 0.2 I started thinking about making a web version. I now have CaltrainJS 0.2 running. Ironically it seems to work OK everywhere except where I most want it to work: Internet Explorer Mobile. The Javascript and CSS support in that browser leaves much to be desired.

There are some refinements I could do for other browsers, like putting the schedule in a scrollable box so that the header would stay in place, but I put that work on hold until I get it working in IE Mobile. (I did have the scrollable area working reasonably well in Firefox.)

Update: I resorted to using innerHTML to (re)write the complete table on each update, since modifying a table dynamically in IE Mobile does not seem to be possible. Marked it CaltrainJS 0.2.1.

Update 2: I just released 0.3 to update to the March 3, 2008 schedules, and fixed the AM/PM bugs.