时间脚本帮助寻求! [英] Time script help sought!

查看:45
本文介绍了时间脚本帮助寻求!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有点像一个果酱(好吧一个大果酱)我希望

这里有人能给我一个快速的手。我有几页时间

计算要做。所以,我刚刚开始在他们的

时间计算器中输入它们并手动编写它们。现在我意识到,我确实需要一个脚本来执行此操作,因为:


1.事实证明这有几百页。

2.我必须尽快做类似的事情。

3.通过手工完成我会引入精彩的新错误!

4这一切都必须打字(这意味着工作周,甚至更多的打字错误!)


输入是这样的:


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模拟磁带声音缺陷。

Item_3 TAPE_1 8 12:58 24: 20模拟磁带声音缺陷。


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电子音响。

Item_4 TAPE_1 14 35:21

Item_4 TAPE_1 15 36:06

Item_4 TAPE_1 16 37:01 37:38


这些是数字化的模拟磁带(在CD或数字磁带上)

现在已被导出为单个文件,这些文件是

在线音频档案的一部分。时间是指CD或数字磁带上的时间显示

。现在所有都必须进行调整,以便每个

项目从0.00开始,因为它们都是从他们的

上下文中编辑的,现在是从00开始的所有单个项目: 00。因此,在磁带上以00:23开始并在8:23结束的Item_1

需要减去

23秒,以便它说:


Item_1 TAPE_1 1 00:00 08:00


Item_2 TAPE_1 2 08:23 09:41


将改为:


Item_2 TAPE_1 2 00:00 01:18




但是一如既往你可能会注意到皱纹....有些物品有很多次

(这里6)表示:


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模拟磁带声音缺陷。

Item_3 TAPE_1 8 12:58 24:20模拟磁带声音缺陷。


这是一个单独的声音文件,这些单独的时间标记

有休息,缺陷,o r编辑单个项目。这些还要调整

以显示这些事件将出现在

新声音文件中的位置,该声音文件现在从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缺陷模拟磁带声音。

Item_3 TAPE_1 8 03:04 14:39模拟磁带声音缺陷。


更多皱纹:有些表示开始和结束时间,一些只有

的开始时间。我认为输出最好是两个......一些

有评论而其他人都不...我需要这些评论回音或

因为我可能需要最终制作一个数据库或表格

评论只有一些占位符。


我会有很多类似的类型计算要做...我希望并且

祈祷这里有人感觉很慷慨并告诉我路然后然后我会修改那个去做其他的任务...通常我很高兴能够走很长的路,所有但我会说实话,我在这里有一个很大的

果酱这个庞大的任务只是倾倒在我身上。坦率地说,我很想在这方面寻求帮助,希望有人能够感受到这一点,并且给我一个明确可修改的例子。对不起.....

欢呼,

凯文

解决方案

" kpp9c" < kp*@mac.com>写道:

这些是数字化的模拟磁带(在CD或数字磁带上)
现在已被导出为单个文件,这些文件应该是一部分在线音频档案。 ......
我希望并且祈祷有人在这里感觉很慷慨并给我指路......




这是否在线公众可以免费访问存档吗?

存档中有什么?如果您要求志愿者工作,那么通常适合准确说明劳动力的用途。


是的,最终,它将成为现场研究人员可用的大型数字档案库的一部分,最终可能会在纽约公共图书馆的新b / b
上线。这是一项艰巨的任务,而且大部分的

声音文件已经完成。我(我们)正在努力应对文件的庞大规模

....抱歉....我本来应该更多

清楚,特别是因为我我有点乞求一点帮助。对不起,我现在稍微不知所措了......


kpp9c写道:

输入是这样的:




[...]


附件是首先剪切一个实际使用原始电子邮件的原始内容

的解析器。您会注意到,净效果是

解析器实例的items属性包含

项的源有序列表,其中包含各个部分的属性这条线。从

这个,它应该很容易调整时间和什么不是。


干杯,


// m


#!/ usr / bin / env python

""" usage:%prog

"""


raw ="""我有点像果酱(好吧大果酱)我希望

这里有人可以快点给我。我有几页时间

计算要做。所以,我刚刚开始在他们的

时间计算器中输入它们并手动编写它们。现在我意识到,我确实需要一个脚本来执行此操作,因为:


1.事实证明这有几百页。

2.我必须尽快做类似的事情。

3.通过手工完成我会引入精彩的新错误!

4这一切都必须打字(这意味着工作周,甚至更多的打字错误!)


输入是这样的:


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模拟磁带声音缺陷。

Item_3 TAPE_1 8 12:58 24: 20模拟磁带声音缺陷。


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电子音响。

Item_4 TAPE_1 14 35:21

Item_4 TAPE_1 15 36:06

Item_4 TAPE_1 16 37:01 37:38


这些是数字化的模拟磁带(在CD或数字磁带上)

现在已被导出为单个文件,这些文件是

在线音频档案的一部分。时间是指CD或数字磁带上的时间显示

。现在所有都必须进行调整,以便每个

项目从0.00开始,因为它们都是从他们的

上下文中编辑的,现在是从00开始的所有单个项目: 00。因此,在磁带上以00:23开始并在8:23结束的Item_1

需要减去

23秒,以便它说:


Item_1 TAPE_1 1 00:00 08:00


Item_2 TAPE_1 2 08:23 09:41


将改为:


Item_2 TAPE_1 2 00:00 01:18




但是一如既往你可能会注意到皱纹....有些物品有很多次

(这里6)表示:


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模拟磁带声音缺陷。

Item_3 TAPE_1 8 12:58 24:20模拟磁带声音缺陷。


这是一个单独的声音文件,这些单独的时间标记

有休息,缺陷,o r编辑单个项目。这些还要调整

以显示这些事件将出现在

新声音文件中的位置,该声音文件现在从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缺陷模拟磁带声音。

Item_3 TAPE_1 8 03:04 14:39模拟磁带声音缺陷。


更多皱纹:有些表示开始和结束时间,一些只有

的开始时间。我认为输出最好是两个......一些

有评论而其他人都不...我需要这些评论回音或

因为我可能需要最终制作一个数据库或表格

评论只有一些占位符。


我会有很多类似的类型计算要做...我希望并且

祈祷这里有人感觉很慷慨并告诉我路然后然后我会修改那个去做其他的任务...通常我很高兴能够走很长的路,所有但我会说实话,我在这里有一个很大的

果酱这个庞大的任务只是倾倒在我身上。坦率地说,我很想在这方面寻求帮助,希望有人能够感受到这一点,并且给我一个明确可修改的例子。对不起.....

欢呼,

凯文


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


导入optparse

导入重新


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


class项目:


def __init __(自我,行):

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 =无

if len (部分)> 5:

self.comment =''''。join(部分[5:])

else:

self.comment = None


class Parser:


def __init __(个体经营):

self.items = []


def feed(self,line):

item = Item(line)

self.items.append(item)


def parseCommandLine(usage,requiredArgCount,argv = None):

"""解析命令行并返回(options,args)。


如果由于requiredArgCount指定的位置参数不足而引发错误



"""

parser = optparse.OptionParser(用法)

## parser.add_option('' - x'',

##'' - xxx'',

## action ='''',

## default ='''',

## help ='''' )

选项,args = parser.parse_args(argv)

如果len(args)< requiredArgCount:

parser.error(''缺少参数。'')

返回选项,args


def main(argv =无):

用法= __doc__

requiredArgCount = 0

options,args = parseCommandLine(usage,requiredArgCount,argv)

filename = args [0]

parser = Parser()

for raw.split(''\ n'')中的行:

如果不是line.startswith(''Item_''):

继续

parser.feed(行)


if __name__ ==''__ main__'':

main()



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

解决方案

"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.


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...


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.append(item)

def parseCommandLine(usage, requiredArgCount, argv=None):
"""Parse the command line and return (options, args).

Raise an error if there are insufficient positional arguments as
specified by requiredArgCount.
"""
parser = optparse.OptionParser(usage)
## parser.add_option(''-x'',
## ''--xxx'',
## action='''',
## default='''',
## help='''')
options, args = parser.parse_args(argv)
if len(args) < requiredArgCount:
parser.error(''Missing parameters.'')
return options, args

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

if __name__ == ''__main__'':
main()


这篇关于时间脚本帮助寻求!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆