Almost too easy

With my new monitor I of course had to get my TV card going again — you might remember that Stéphanie and I had stopped watching TV?… Not anymore, we’re now quite normal again :-)

Configuring tvtime is fairly easy, but reordering the channels is somewhat annoying since you have to specify their position with an attribute in the stationslist.xml file, which looks like this:

<?xml version="1.0"?>
<!DOCTYPE stationlist PUBLIC "-//tvtime//DTD stationlist 1.0//EN"
<stationlist xmlns="">
  <list norm="PAL" frequencies="europe">
    <station name="DR1" active="1" position="1" band="VHF E2-E12" channel="E5" finetune="0" norm="PAL" audio="auto"/>

I would have gone for the simple solution where the document order would determine the relative position of the channels since I find it much easier to reorder the lines than updating the attributes.

Luckily it was very easy for me to edit the XML file to suit my need using the excellent Beautiful Soup Python library. I simply did this in an interactive Python session:

>>> from BeautifulSoup import BeautifulStoneSoup
>>> soup = BeautifulStoneSoup(open('.tvtime/stationlist.xml', 'r'))
>>> for i, station in enumerate(soup.findAll('station')):
...   station['position'] = i+1
>>> soup

after which I got the changed XML in the terminal, which I could then copy-paste into the file. The result was a nice file where the position attribute reflected the document order, just as I wanted it!


  1. Kristian Kristensen:

    You gotta love a solution like that! True geekdom.
    Glad to see you’re back in “the real world” with TV ;-)

  2. Thomas:

    Yeah, that is kinda geeky - great :)

  3. Martin Geisler:

    Hehe, thanks! :-)

  4. Ryu:

    Hi Martin, I tried to do this but position attributes didn’t reflect document order.

    Here are my first 4 station lines in the output file:

    As you see position attributes aren’t correct.

    Am I doing something wrong?

    Could you please reply by e-mail? Thanks!

  5. Ryu:

    sorry, here are those lines:

    station name=”TRT 1″ active=”1″ position=”1″ band=”VHF E2-E12″ channel=”E8″ finetune=”0″ norm=”PAL” audio=”auto”
    station name=”TRT 2″ active=”1″ position=”2″ band=”VHF E2-E12″ channel=”E9″ finetune=”0″ norm=”PAL” audio=”auto”
    station name=”KANAL D” active=”1″ position=”40″ band=”VHF S1-S41″ channel=”S28″ finetune=”0″ norm=”PAL” audio=”auto”
    station name=”SHOW TV” active=”1″ position=”6″ band=”VHF E2-E12″ channel=”E6″ finetune=”0″ norm=”PAL” audio=”auto”

  6. Martin Geisler:

    Hi Ryu, I don’t know why it doesn’t work… maybe it is because the above code is only a snippet of what I ended up using:

    from os.path import expanduser
    from BeautifulSoup import BeautifulStoneSoup
    f = file(expanduser('~/.tvtime/stationlist.xml'), 'r+')
    soup = BeautifulStoneSoup(f, selfClosingTags=['station'])
    for i, station in enumerate(soup.findAll(’station’)):
        station['position'] = i+1

    That really ought to work! It will overwrite your current ~/.tvtime/stationlist.xml file, so you might want to make a backup of it first, just in case :-)

  7. free quotes:

    Thank you, I just wanted to give a greeting and tell you I like your website very much.

  8. Abigail Gatica:

    You are my aspiration , I have few web logs and infrequently run out from to brand : (.

Leave a comment