Exploratory query

Discussion in 'Python' started by Don Todd, Aug 5, 2003.

  1. Don Todd

    Don Todd Guest

    I'm a total python newbie and have not really even begun to learn.
    Before I start, however, I would like to know if python is the proper
    tool for what I want to do.

    I want to query various MH mailboxes to see if they contain new mail.
    There is a program, flist, that will do this, but it is a pain to run it
    every time. I'd like something a la xbiff or gbiffy.

    Would python allow me to run flist and use its output, or would I need
    to re-write flist? The idea is to keep something on the screen and poll
    the mailboxes every n seconds and update the display.

    TIA,

    dt
     
    Don Todd, Aug 5, 2003
    #1
    1. Advertising

  2. Don> Would python allow me to run flist and use its output, or would I
    Don> need to re-write flist? The idea is to keep something on the screen
    Don> and poll the mailboxes every n seconds and update the display.

    You can do this quite easily. Presuming you just want to display flist's
    output for now, but maybe mangle it later, you can probably get away with
    something simple like this:

    import time
    import commands

    while True:
    status, output = commands.getstatusoutput("flist")
    if status != 0:
    print "flist barfed... exiting"
    # right here you could massage output
    print output
    time.sleep(300) # five minutes

    Skip
     
    Skip Montanaro, Aug 5, 2003
    #2
    1. Advertising

  3. Don Todd

    Don Todd Guest

    In article <>, Skip Montanaro wrote:
    >
    > Don> Would python allow me to run flist and use its output, or would I
    > Don> need to re-write flist? The idea is to keep something on the screen
    > Don> and poll the mailboxes every n seconds and update the display.
    >
    > You can do this quite easily. Presuming you just want to display flist's
    > output for now, but maybe mangle it later, you can probably get away with
    > something simple like this:
    >
    > import time
    > import commands
    >
    > while True:
    > status, output = commands.getstatusoutput("flist")
    > if status != 0:
    > print "flist barfed... exiting"
    > # right here you could massage output
    > print output
    > time.sleep(300) # five minutes
    >
    > Skip


    Thanks, Skip! That pretty much does what I want; I modified it to do
    "flist mailbox1", "flist mailbox2" etc.

    Is there a way to run this in a terminal and have it uptate the new over
    the old? I'm thinking it would be sweet to run it in tranparent
    terminal. Perhaps I'll look into using a gui, too.

    dt
     
    Don Todd, Aug 5, 2003
    #3
  4. >>>>> "Don" == Don Todd <> writes:

    Don> In article <>, Skip Montanaro wrote:
    >>

    Don> Would python allow me to run flist and use its output, or would I
    Don> need to re-write flist? The idea is to keep something on the screen
    Don> and poll the mailboxes every n seconds and update the display.
    >>
    >> You can do this quite easily. Presuming you just want to display flist's
    >> output for now, but maybe mangle it later, you can probably get away with
    >> something simple like this:
    >>
    >> import time
    >> import commands
    >>
    >> while True:
    >> status, output = commands.getstatusoutput("flist")
    >> if status != 0:
    >> print "flist barfed... exiting"
    >> # right here you could massage output
    >> print output
    >> time.sleep(300) # five minutes
    >>
    >> Skip


    Don> Thanks, Skip! That pretty much does what I want; I modified it to
    Don> do "flist mailbox1", "flist mailbox2" etc.

    Also, note that I forgot the break statement in the exit branch. Should
    have been:

    if status != 0:
    print "flist barfed... exiting"
    break

    Don> Is there a way to run this in a terminal and have it uptate the new
    Don> over the old? I'm thinking it would be sweet to run it in
    Don> tranparent terminal. Perhaps I'll look into using a gui, too.

    Sure. There are a couple ways to do it. The crude way might just be to put


    commands.getstatusoutput("clear")

    at the top of the list. The cleaner way would probably be to use the
    curses module. I've no experience to make any suggestions, but the curses
    module docs at

    http://www.python.org/doc/current/lib/module-curses.html

    have a link to Andrew Kuchling's "Curses with Python" tutorial.

    Skip
     
    Skip Montanaro, Aug 5, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Learner
    Replies:
    1
    Views:
    1,008
    Marina Levit [MVP]
    Jan 30, 2006
  2. Anonymous
    Replies:
    0
    Views:
    1,531
    Anonymous
    Oct 13, 2005
  3. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    818
    David Gordon
    May 18, 2005
  4. Eric Nelson
    Replies:
    5
    Views:
    1,559
    Alexey Smirnov
    Feb 4, 2009
  5. Brian Marick

    Exploratory testing with Ruby

    Brian Marick, May 14, 2004, in forum: Ruby
    Replies:
    8
    Views:
    124
    Phil Tomson
    May 17, 2004
Loading...

Share This Page