forked from CryHavoc/dottes
Add --index parameter to allow selection of nth occurence of field.
This commit is contained in:
parent
6f50649440
commit
e6090d8ef4
12
abcfield.py
12
abcfield.py
|
@ -105,11 +105,15 @@ def convertTitle(t, options):
|
|||
return res
|
||||
|
||||
def process(inf, options):
|
||||
n = options.index
|
||||
for line in inf:
|
||||
line = line.strip()
|
||||
if len(line) > 2 and line[0] == options.field and line[1] == ':':
|
||||
print(convertTitle(line[2:].strip(), options))
|
||||
break
|
||||
if n > 1:
|
||||
n = n - 1
|
||||
else:
|
||||
print(convertTitle(line[2:].strip(), options))
|
||||
break
|
||||
|
||||
parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n"
|
||||
" Extract field data from ABC file.")
|
||||
|
@ -121,6 +125,10 @@ parser.add_option("-m", "--html", dest="html",
|
|||
parser.add_option("-l", "--latex", dest="latex",
|
||||
action="store_true", default=False,
|
||||
help="format ouput for LaTeX")
|
||||
parser.add_option("-n", "--index", dest="index",
|
||||
action="store", type="int", default=1,
|
||||
help="report INDEXth value [default: %default]",
|
||||
metavar="INDEX")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if options.html and options.latex:
|
||||
|
|
Loading…
Reference in New Issue