From 37c010cba06f635e37428b8d8b6d18beef75fc7b Mon Sep 17 00:00:00 2001 From: Quillot Mathias Date: Wed, 28 Apr 2021 21:09:05 +0200 Subject: [PATCH] Filter works well now --- volia/data.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/volia/data.py b/volia/data.py index 8261d81..e4e7728 100644 --- a/volia/data.py +++ b/volia/data.py @@ -3,34 +3,44 @@ import sys from utils import SubCommandRunner +import core.data + # Main parser parser = argparse.ArgumentParser(description="manage files") subparsers = parser.add_subparsers(title="actions") - - # Filter ids parser_filter = subparsers.add_parser("filter", help="filter a file") -parser_filter.add_argument("--file", type=str, help="path of the file to filter") -parser_filter.add_argument("--filter", type=str, help="filter file [id_from] [id_to]") +parser_filter.add_argument("--file", type=str, help="path of the file to filter", required=True) +parser_filter.add_argument("--filter", type=str, help="filter file [id_from] [id_to]", required=True) +parser_filter.add_argument("--outfile", type=str, help="output file", required=True) parser_filter.set_defaults(which="filter") # Convert parser_convert = subparsers.add_parser("convert", help="convert a file") -parser_convert.add_argument("--file", type=str, help="...") -parser_convert.add_argument("--type-from", type=str, choices=["old-masseffect", "new-masseffect"], help="...") -parser_convert.add_argument("--type", choices=["old-masseffect", "new-masseffect"]) +parser_convert.add_argument("--file", type=str, help="...", required=True) +parser_convert.add_argument("--type-from", type=str, choices=["old-masseffect", "new-masseffect"], help="...", required=True) +parser_convert.add_argument("--type", choices=["old-masseffect", "new-masseffect"], required=True) parser_convert.set_defaults(which="convert") - # Parse args = parser.parse_args() -def filter_file(file_path, filter_path): - pass +def filter_file(file, filter, outfile): + file_path = file + filter_path = filter + file_data = core.data.read_id_values(file_path) + filter_data = core.data.read_lst(filter_path) + + with open(outfile, "w") as out: + for id_ in filter_data: + core.data.write_line(id_, file_data[id_], out) + + + def convert(file, type_from, type): pass -- 1.8.2.3