Commit 1b485707 authored by Neeme Kahusk's avatar Neeme Kahusk

tablefile ja style args

parent cf427740
0.4.1
\ No newline at end of file
0.4.2
\ No newline at end of file
......@@ -13,11 +13,12 @@ from pathlib import Path
from lxml import etree
from prepare import read_xml
from configure_columns import SIMPLE, NAMES, NAMES_ATA, LONG
#from configure_columns import SIMPLE, NAMES, NAMES_ATA, LONG
import configure_columns
#XPATHLIST = NAMES_ATA
#XPATHLIST = NAMES
XPATHLIST = LONG
#XPATHLIST = LONG
class Name(object):
def __init__(self):
......@@ -60,7 +61,7 @@ class Person(object):
self.communicationInfo = None
def make_filter(tabelifail: str = 'tulbad.csv') -> list:
def make_filter(tabelifail: str, xpathlist: list) -> list:
"""Reads "columns file" (columns 'label', 'simplepath', 'xpath' etc. and returns
possible list of labels (possible columns for query).
......@@ -71,7 +72,7 @@ def make_filter(tabelifail: str = 'tulbad.csv') -> list:
reader = csv.DictReader(tf, dialect=csv.excel_tab)
csvdata = [x for x in reader]
labels_et = [x for x in csvdata if x['label_et'] in XPATHLIST]
labels_et = [x for x in csvdata if x['label_et'] in xpathlist]
return labels_et
......@@ -159,16 +160,26 @@ def csv_out(outfilename: str, data: list, headers: list):
writer.writerow(i)
def styleset(istring: str) -> str:
arguments = [v for v in dir(configure_columns) if v[:2] != "__"]
if istring.upper() not in arguments:
print (istring)
raise argparse.ArgumentTypeError
return istring
def main():
parser = argparse.ArgumentParser(description='Converts resource description(s) from xml file(s) to csv file.')
parser.add_argument('infile')
parser.add_argument('outfile')
parser.add_argument('-t', '--tablefile', default='tulbad.csv')
#parser.add_argument('-x', '--xpath')
parser.add_argument('-s', '--style', #type=styleset,
choices=[v.lower() for v in dir(configure_columns) if v[:2] != "__"],
default='simple')
args = parser.parse_args()
labels = make_filter(args.tablefile)
labels = make_filter(args.tablefile, args.style)
if is_zipfile(args.infile):
tulem = zip2roots(args.infile)
......@@ -180,7 +191,13 @@ def main():
tulem = [read_xml(args.infile)]
tulemitabel = featured_rows(tulem, labels)
csv_out(args.outfile, tulemitabel, XPATHLIST)
csv_out(args.outfile, tulemitabel, args.style)
def test():
#print([v for v in dir(configure_columns) if v[:2] != "__"])
print([v for v in dir(configure_columns)])
if __name__ == '__main__':
#test()
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment