Time script help sought!

sp1d3rx at gmail.com sp1d3rx at gmail.com
Tue Jan 11 14:14:32 EST 2005


read below for my sample script....

kpp9c wrote:
> I am kind of in a bit of a jam  (okay a big jam) and i was hoping
that
> someone here could give me a quick hand. I had a few pages of time
> calculations to do. So, i just started in on them typing them in my
> time calculator and writing them in by hand. Now i realize, that i
> really need a script to do this because:
>
> 1. It turns out there are hundreds of pages of this stuff.
> 2. I have to do something similar in again soon.
> 3. By doing it by hand i am introducing wonderful new errors!
> 4. It all has to be typed up anyway (which means weeks of work and
even
> more typos!)
>
> The input would like so:
>
> Item_1    TAPE_1    1    00:23    8:23
>
> Item_2    TAPE_1    2    8:23    9:41
>
> Item_3    TAPE_1    3    9:41    10:41
> Item_3    TAPE_1    4    10:47    11:19
> Item_3    TAPE_1    5    11:21    11:55
> Item_3    TAPE_1    6    11:58    12:10
> Item_3    TAPE_1    7    12:15    12:45    Defect in analog tape
sound.
> Item_3    TAPE_1    8    12:58    24:20    Defect in analog tape
sound.
>
> Item_4    TAPE_1    9    24:33
> Item_4    TAPE_1    10    25:48
> Item_4    TAPE_1    11    29:48
> Item_4    TAPE_1    12    31:46
> Item_4    TAPE_1    13    34:17        Electronic sounds.
> Item_4    TAPE_1    14    35:21
> Item_4    TAPE_1    15    36:06
> Item_4    TAPE_1    16    37:01    37:38
>
> These are analog tapes that were digitized (on to CD or a digital
tape)
> that have now been exported as individual files that are meant to be
> part of an on-line audio archive. The timings refer to the time
display
> on the CD or digital tape. The now all have to adjusted so that each
> item starts at 0.00 since they have all been edited out of their
> context and are now all individual items that start at 00:00. So
Item_1
> which was started at 00:23 on the tape and ended at 8:23 needs to
have
> 23 seconds subtracted to it so that it says:
>
> Item_1    TAPE_1    1    00:00    08:00
>
> Item_2    TAPE_1    2    08:23    09:41
>
> would change to:
>
> Item_2    TAPE_1    2    00:00    01:18
>
> etc.
>
> but as always you may notice a wrinkle.... some items have many times
> (here 6) indicated:
>
> Item_3    TAPE_1    3    9:41    10:41
> Item_3    TAPE_1    4    10:47    11:19
> Item_3    TAPE_1    5    11:21    11:55
> Item_3    TAPE_1    6    11:58    12:10
> Item_3    TAPE_1    7    12:15    12:45    Defect in analog tape
sound.
> Item_3    TAPE_1    8    12:58    24:20    Defect in analog tape
sound.
>
> This is all a single sound file and these separate times mark where
> there was a break, defect, or edit in the individual item. These have
> to be adjusted as well to show where these events would appear in the
> new sound file which now starts at 00:00.
>
> Item_3    TAPE_1    3    00:00    01:00    ----
> Item_3    TAPE_1    4    01:00    01:38    ----
> Item_3    TAPE_1    5    01:38    02:14    ----
> Item_3    TAPE_1    6    02:14    02:29    ----
> Item_3    TAPE_1    7    02:29    03:04    Defect in analog tape
sound.
> Item_3    TAPE_1    8    03:04    14:39    Defect in analog tape
sound.
>
> Further wrinkles: Some have start and end times indicated, some only
> start times. I suppose that the output would ideally have both....
some
> have comments and others don't ... and I need these comments echo-ed
or
> since i probably need to make a database or table eventually non
> comments just have some place holder.
>
> I'd have a lot of similar type calculations to do... I was hoping and
> praying that some one here was feeling generous and show me the way
and
> then, of course i could modify that to do other tasks... Usually i am
> happy to take the long road and all but i'll be honest, i am in a big
> jam here and this huge task was just dumped on me. I am frankly a
> little desperate for help on this and hoping someone is feeling up to
> spoon feeding me a clear modifiable example that works. Sorry.....
> cheers,
>
> kevin
--------START--------
inp = file("input1.txt",'r') # input file is opened readonly
x = inp.readline() #read in the first line of the file
x = x.upper().split(None,5) #convert it to uppercase and split into 5
segments
print x #show the line as splitted and converted
print x[1] #show the second element
start = x[3].split(":") #split the minutes from the seconds
end = x[4].split(":") #split the minutes from the seconds
print "Start at:", start[0], "minutes and ", start[1], "seconds."
start_in_seconds = int(start[0])*60 + int(start[1]) #converts
minutes/seconds to seconds
print start_in_seconds , "seconds offset."
print "End at:", end[0],"minutes and",end[1], "seconds."
end_in_seconds = int(end[0])*60 + int(end[1])#converts minutes/seconds
to seconds
print end_in_seconds , "seconds offset."
totaltime = end_in_seconds - start_in_seconds #calculate the length of
the segment
print "Total time of segment in seconds:", totaltime
print "Total time of segment in minutes/seconds:", totaltime/60,
"minutes and", totaltime % 60, "seconds."
# ^^^ converts seconds back to minutes and seconds.
--------END--------

This should give you an excellent starting point.




More information about the Python-list mailing list