TrafficCam, Version 3

Apparently, when the TrafficCam flash program was released, Justin was opening a can of worms that was bigger than I could have imagined.

After my example of quick development on the Python app, I got a lot of interest in my own TrafficCam application. Suddenly, there was a London version. And a Dubai version. And every time I mentioned it, someone else wanted to create their own version and load it in so that they could use the same nifty features. If there’s one thing that I do right, it’s listen to what my users are telling me. So, this afternoon, upon the arrival about my new Nokia 6600, I got to work.

First step: Build a file loader. This function should take a file of predefined format and read it in over the web, letting you specify some parameters to the program. This data should then be returned in a way that the application can use. We can’t make the file format too complex: the default Python install comes with no XML support, remember, so we’re using a very basic, tab delimited layout for this. The format is pretty simple: It’s described in the TrafficCam Format Documentation, for those of you who may want to use it.

Step two: Build the app around the data. Given a specific URL, construct the entire application setup, from the tabs to the title to listings, from that returned data. Not too hard: required a little bit of changing how I did things so that it could be reloaded easily, but as always, Python was cooperative.

Step Three: Build a frontend to choosing URLs to load data from. Store a title an a URI, and let people choose which to load. Not too bad: using the popup_menu that symbian provides, can easily associate the resulting choice with your earlier list.

Step Four: Add support for reloading. Once I’m done with one set of cameras, I want to view another without having to exit and restart. This is a bit more complex: it requires me to move some of the logic around so that the application flow stays mostly the same. In the end, I ended up cleaning up some ugly repetition of the code this way, which was useful.

Step Five: Make it more user friendly. Add an “Other” for choosing their own URLs, add progress meters and information boxes, put in exception support for when a URI doesn’t load correctly, and in general, make the app work better.

All in all, I spent six hours yesterday working on the application, and basically rewrote it from top to bottom. It’s now easy to use, and extendable to do whatever people want. I can admit that it’s probably the single most user-friendly application I’ve ever written: almost all my work in the past has been command line based, but this is truly a cool application.

If you have a phone which supports Python, I highly recommend this application. Although I’m sure there are better apps out there, this one is my personal favorite: lets you get a glimpse of the world through your phone. Of course, you should be aware that this is not a low bandwidth application: the camera listings are only about 3-4k apiece, but each camera image can be anywhere from 10-15k, sometimes more depending on the cameras you’re using. Yesterday, while doing development, I used up a megabyte of GPRS bandwidth – luckily, I have unlimited GPRS through my provider.

If you live in an area where there are traffic cameras, and you’d like to see them added, simply construct a file according to the format documentation, and drop me a line.

Have I mentioned lately that I love Python?

Now, to get working on that contact database export I had in mind…

13 Responses to “TrafficCam, Version 3”

  1. Larry Cummings Says:


    Just hacked out a Phoenix Traffic Cam version of this script. Not a real strong Python coder, but the ease with which I did this, and my new nokia 6600 are definately getting me excited about it!

    I’m having a problem in that it doesn’t seem to work when a leading zero appears in a camera name. They use a three digit code for the cameras wich results in camera image names like “camera010.jpg”.

    (all the cams that don’t have leading zeros in their names seem to work fine).

    I’ll post the formatted file later today.

    Thanks for this script, it’s great!


  2. Christopher Schmidt Says:

    Larry – I know that in the previous version, this could have been an issue, but in the latest one, it shouldn’t be: it should use the string you specify. (The reason is I was using an int() cast due to some laziness on my part, which I have since changed.) If you did it in the version 2 script, you should change the int(k[id]) to just be k[id] : this is already taken care of in the newest version of the code.

    Glad to see that you liked it, and looking forward to seeing the Phoenix cams!

  3. Kashif Khan Says:

    Hi there Christoper,

    I have modified the first version for houston cams. You can have a look at it here .

    Excellent job by the way. This is my first project for a mobile phone and has really got me interested in it.

  4. Alasdair Allan Says:

    I’ve also gone off and written my own version of your inital applicaiton. However, I’ll grab your latest version and work from there, as you’ve done exactly what I was going to do next, fetch the list of URLs from a remote site.

    I think this sort of thing really shows how useful a decent high level language for mobile development is going to be, it’s just so much easier to work with than Java ME ever was…

  5. Ron Says:

    I own a new Yahoo group called “Traffic-Cams” . i have looked at your website and i am very interested
    in your traffic-cam application i guess the other members of my group would be interested too
    Now..i am a little confused and cannot complety understand what your application is for
    i suppose it is for a nokia cellphone and it has preprogrammed url’s …it will alow you to see these cams
    on this cellphone ..many things are not clear to me like: will it do video,streaming jpg’s or just stills ?

    My question is: would you become a member of our group and do a short introduction of what this is all about ?
    i am shore our members would appriciate that.
    The group can be found here:
    It would be of interest to you anyway since we have the most extensive list of all traffic-cams in the world
    nicely sorted by country or technical details.
    You are welcome ! hope to hear from you soon Thanks !

    Ron (contranl) moderator of Yahoo traffic-cams

  6. Luca Says:


    I’m working on my .dat file but I receive an “ill line” while the application parse s it! Any suggestion is very appreciated!


  7. Alasdair Allan Says:

    Christopher, spotted your comment and was wondering if you’d point to as the “cannonical” list of Devon cameras, I’ll try and keep it up to date and add new ones as I find them. In fact if I get time this week I’ll try and do the rest of the U.K. outside of London, as there are several digestable lists of cameras lying around. The U.K. being more or less divided into London, England and “other”… and that’s coming from a Scotsman as well.

  8. Dan Connolly Says:

    re “We can’t make the file format too complex: the default Python install comes with no XML support, remember, so we’re using a very basic, tab delimited layout for this.” parsing ordinary XML (with no parameter entities, etc.) in pure python can be really easy. See my VHS index and the thingy that has a 3-line XML parser:

    def tags(markup):
        """quick-n-dirty XML parser
        for tag in markup.split(">"):
            yield tag

    hmm… no comment preview… I hope this turns out OK…

  9. Christopher Schmidt Says:

    Alasdair: If you’re up to ensuring that the format you put up won’t fail, I’d be glad to set it there for you. My main concern is with setting them to files which might change and be unparseable: the error handling in this case is pretty sucky at the moment. If you’re willing to test before you update, then I’ll set it there. Let me know.

    Luca: You’re using a platform which uses two characters for line endings, most likely windows, \r\n. The loader expects only one character line endings, so when it loads your tabs line, the key for the final value is given an extra character (‘s\r’) and your s keys can’t be set because of it. You want to run the file through a program called “dos2unix” in order to fix it up. Alternatively, you can offer a patch to the loader which is smarter, which I’ll also take. Look around the “readline” parts.

    DanC: Although it’s true that you can do something simple like that, it doesn’t do what most people want from XML: If I were to go with a “simple” XML parsing solution like that, I’d simply run into people putting more than it could handle into it (comments, for example) and wondering why it didn’t work. I’d rather lay out a very simple, non-extensible format, since then people don’t expect it to work without putting some work in it 😉 One of the problems that many people seem to have with XML is that they expect that if they write it an XML file, everyone will be able to read it. (Silly, I know, but it happens.) So, I suppose I’d just prefer my nice simple format to keep things happy with people who don’t realize why their file might not work..

  10. Julie Szurko Says:

    Nothing to do with your site really. I was searching my family surname Szurko and noticed a Matt Szurko on this site. We are looking for relatives so would be interested to chat.

  11. Outside the box Says:

    Python delivers Traffic Cameras on Nokia’s Series 60 Platform

    Here’s the Arizona data required to get Craig Schmidt’s Python script (for Nokia Series 60 devices) to deliver Traffic Cams to mobile devices.

  12. Luca Says:

    Hi Christopher,

    Thanks for your help! Now it works. I went through the “dos2unix” option then. I’ll leave the .dat file on that uri to be accessed by others.


  13. LonelyBob Says:

    Version including cams from Tokyo, Japan
    Took alittle while figuring out the windoze 2 character /t/r prob but using dos2unix fixed that thanks to Luca’s post.