#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    13
    Rep Power
    0

    Every Minute, Compare Values


    I have 2 lists (list a, list b) and I need to compare them
    against each other to find the differences. The lists hold
    a timestamp and information about certain shell scripts that
    should run (list a) and what did run (list b).

    Example:
    Code:
    list a (scripts should have ran)
    'Thu Jun 17 11:30 /path/to/shell/script.sh'
    'Thu Jun 17 5:30 /path/to/shell/aScript.sh'
    
    list b (scripts that did run)
    'Thu Jun 17 11:30 /path/to/shell/script.sh'
    
    didnt run (was not in list b)
    Thu Jun 17 5:30 /path/to/shell/aScript.sh
    To compare them, I have to loop through each minute of the
    day to see if the script is eligible to run at that time
    (ex: list a is eligible to run at 11:30). If it is eligible run,
    (its 11:30 in this case, so script can run) then I need to compare the lists to see
    if list a is equal to list b (basically, list b has a matching value).

    Can some help/point me in the right direction? I have the two
    lists built (a & b), but I am unsure on how to start looping
    through each minute of the day & then compare if the 2 values
    to see if they are equal or the same. If they are the same,
    I want to append that info to a new list (list c) OR if they
    are not the same, I want to append that info to a new list (list d).

    Any help would be greatly appreciated.

    Thanks In Advance!
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You're looking for the time.sleep() function, which takes one value; the number of seconds you want the program to wait for. So all you need to do is put this in a while True loop i.e.

    Code:
    while True:
        time.sleep(60)
        ...
        do action here
        ...
    I've also written a cron class, which you might be interested in: http://forums.devshed.com/t113931/s.html

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    13
    Rep Power
    0
    Thank you for replying back with sleep function idea!
    I tried using it, but I have decided to grab all the minutes of the day in a list:

    Code:
        def todaysMinutes():
            year, month, day = time.localtime()[0:3]
            for hour in xrange(0, 24):
                for minute in xrange(0, 60):
                    t = (year, month, day, hour, minute, 0, 0, 0, 0)
                    yield time.strftime("%a %b %d %H:%M", t)
    
        minuteList = list(todaysMinutes())
    Not sure on this, but I think this will allow me to: check if the script is eligible to run that minute, then compare my lists, then append to a 3rd list of differences.

    Thanks
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Germany
    Posts
    11
    Rep Power
    0
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    13
    Rep Power
    0
    thanks everyone for your help on this topic!

IMN logo majestic logo threadwatch logo seochat tools logo