473,803 Members | 3,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time script help sought!


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

Jul 18 '05 #1
15 2035
"kpp9c" <kp*@mac.com> writes:
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. ...
I was hoping and
praying that some one here was feeling generous and show me the way...


Is this online archive going to be accessible by the public for free?
What's in the archive? If you're asking for volunteer labor it's
generally appropriate to say precisely what that the labor is for.
Jul 18 '05 #2
Yes, Ultimately it will be part of a large digital archive available
for researchers on site and eventually probably on-line for the New
York Public Library. It is a huge undertaking and most of the
soundfiles have been made. I (we) are struggling with the sheer size
of the documentation.. .. Sorry about that.... i should have been more
clear, epecially since i am sort of begging for a little help. Sorry, i
am slightly overwhelmed at the moment...

Jul 18 '05 #3
kpp9c wrote:
The input would like so:


[...]

Attached is a first cut at a parser that actually uses the raw content
of your original email. You'll notice that the net effect is that the
parser instance's items attribute contains the source ordered list of
items with attributes for each of the various parts of the line. From
this, it should be pretty easy to adjust the times and what not.

Cheers,

// m

#!/usr/bin/env python

"""usage: %prog
"""

raw = """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

-- http://mail.python.org/mailman/listinfo/python-list """

import optparse
import re

pat = re.compile('\s+ ')

class Item:

def __init__(self, line):
parts = pat.split(line)
self.name, self.tape, self.number, self.start = parts[:4]
if len(parts) == 5:
self.end = parts[4]
else:
self.end = None
if len(parts) > 5:
self.comment = ' '.join(parts[5:])
else:
self.comment = None

class Parser:

def __init__(self):
self.items = []

def feed(self, line):
item = Item(line)
self.items.appe nd(item)

def parseCommandLin e(usage, requiredArgCoun t, argv=None):
"""Parse the command line and return (options, args).

Raise an error if there are insufficient positional arguments as
specified by requiredArgCoun t.
"""
parser = optparse.Option Parser(usage)
## parser.add_opti on('-x',
## '--xxx',
## action='',
## default='',
## help='')
options, args = parser.parse_ar gs(argv)
if len(args) < requiredArgCoun t:
parser.error('M issing parameters.')
return options, args

def main(argv=None) :
usage = __doc__
requiredArgCoun t = 0
options, args = parseCommandLin e(usage, requiredArgCoun t, argv)
filename = args[0]
parser = Parser()
for line in raw.split('\n') :
if not line.startswith ('Item_'):
continue
parser.feed(lin e)

if __name__ == '__main__':
main()

Jul 18 '05 #4
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.tx t",'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_second s = int(start[0])*60 + int(start[1]) #converts
minutes/seconds to seconds
print start_in_second s , "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_second s #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.

Jul 18 '05 #5
Gosh Mark you must be a friggin genius or something. I can't even begin
to read your code. Anyways, I think mine is easier to understand. My
program has all the functions (save a couple) that you would need for
your project. It's an exercise for you to copy and paste what you want
where you want it and to form a basic program structure out of it. some
of my comments spilled on to the next line (thanks google!) so you will
have to clean it up a bit.

Jul 18 '05 #6
Thanks for this Everyone!

Trying to work with all the stuff folks are giving me on this i a have
come across a problem... down
the line i notice that some of the times will also have an hour as well
as in H:M:S (e.g. 1:22:40)

so in some cases i would need to convert H:M:S to sec and some just M:S
or should there just be a fun that passes all the times and converts
them to H:M:S first and
just appends a 00: ((e.g. 00:02:07) if there is no hour value?
cheers,

-kp

Jul 18 '05 #7
using my code above...
start = x[3].split(":") #split the minutes from the seconds
this splits something like 1:22:40 into three parts
1(hours), 22(mintes), 40(seconds)
so, you must add a special case handler...
if len(start) == 3:
{
start[1] = int(start[0]) * 60 + int(start[1])
start = start[1], start[2]
}
and there you go....
what this does is take the hours , multiply them by 60 and add it to
the minutes.
You will also have to change your output function to convert from
"seconds" to "hours, minutes, seconds".

Jul 18 '05 #8
I also notice that there is the is the 'datetime' module, which is new
to version 2.3, which i now have access to. My feeling is that this
will do much of what i want, but i can't get my head round the standard
library reference stuff

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

I don't have any texts with me either and it probably is too new to be
in the Python Standard Library book by Fredrik Lundh or the Python
Essential Reference by David Beazley
-kevin-

Jul 18 '05 #9
post your script here so we can go over it with you.

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7827
by: lawrence | last post by:
Suppose I create dynamic web pages with 3 functions (which call other functions to make everything happen, but these 3 you might think of as being the top layer): registerSessions(); sendHtmlToBrowsers(); incrementPageViews(); Is there any chance that incrementPageViews() will be executed? Or, to
4
2123
by: Bryan | last post by:
can someone explain to me why i get different values for the tm_yday and tm_isdst values? >>> import rfc822 >>> rfc822.parsedate('Mar 1 01:03:59 2004') (2004, 3, 1, 1, 3, 59, 0, 0, 0) >>> import time >>> time.strptime('Mar 1 01:03:59 2004', '%b %d %H:%M:%S %Y') (2004, 3, 1, 1, 3, 59, 0, 61, -1)
16
2496
by: Andy Dingley | last post by:
I've just had a call from these people, http://www.browsealoud.com offering to sell me their wares. Anyone have an opinion on it ? I'll post my own thoughts about 24 hours from now. I'm interested in what others think - wouldn't want to prejudice other's comments.
0
1822
by: Anurag | last post by:
Hi, ENV: DB2 ESE 8.2.3 DPF (11 nodes) on AIX 5.x ==== SCENARIO / SETUP ======== ====== (1) I needed to find out CPU Time (User / System) of SQL queries for benchmark testing. (2) I setup an EVENT MONITOR WHERE AUTH_ID = 'ANURAG' (write to table).
2
1486
by: shery | last post by:
hi plz help me out i need a php script i have made a link in my website for feedback and i need a good script (php) which will sought out the problem for me ..plus if some one is having a good programme for inserting a online forum in my site.. waiting for a good relpy
2
1157
by: Toadfather | last post by:
Hi all Exiting COM ATL DLL wrapping a C++ library. Interoping from a C# application, passing a large string containng XML (5-130kb). Need to significantly improve performance of both the interoping and the performance of the native functions (performance critical app). Opinions sought on most worthwhile course of action...have identified 4 options...
5
3534
by: Ray Tomes | last post by:
Hi Folks I am an old codger who has much experience with computers in the distant past before all this object oriented stuff. Also I have loads of software in such languages as FORTRAN and BASIC, QBASIC etc that is very useful except that it really doesn't like to run on modern operating systems and has hopeless graphics resolution and lack of ease of use in some ways.
18
9824
by: barry | last post by:
I'm having a problem creating a delay before each list item gets moved ( http://www.polisource.com/PublicMisc/list-splitter-timeout-bug.html ). Choose any number of columns, vertical layout, and view as a web page. They'll be a small delay before the entire bunch of list items converts from left-to-right to top-to-bottom order. I expected a delay before each item is moved. It looks like I have to flush the buffer to get setTimeout to work,...
1
1777
by: dpalepu | last post by:
I am working with the ASP.NET 2.0 Wizard control. I have requirement for generating a popup window onclick of finish button in that Wizard control's finishing step. any ideas or help is sought.
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.