fixed mappings added dir_mode
This commit is contained in:
parent
21a715149e
commit
95e95f407f
78
__init__.py
78
__init__.py
@ -1,26 +1,39 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from table_handler.serializer import TableSerializer
|
import os
|
||||||
from logger import logger
|
from logger import logger
|
||||||
|
|
||||||
|
from table_handler.serializer import TableSerializer
|
||||||
import instructions.countings_formater as countings_formater
|
import instructions.countings_formater as countings_formater
|
||||||
import instructions.ring_formater as ring_formater
|
import instructions.ring_formater as ring_formater
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def process_file(input_file, output_file, formatter, row_instructions):
|
||||||
|
logger.info(f"Processing: {input_file}")
|
||||||
|
|
||||||
|
serializer = TableSerializer(
|
||||||
|
input_file,
|
||||||
|
formatter.EXPECTED_INPUT_TABLE_SCHEMA,
|
||||||
|
formatter.EXPECTED_OUTPUT_TABLE_SCHEMA
|
||||||
|
)
|
||||||
|
|
||||||
|
serializer.run(
|
||||||
|
formatter.COL_INSTRUCTIONS,
|
||||||
|
row_instructions
|
||||||
|
)
|
||||||
|
|
||||||
|
serializer.write_output(output_file)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Serialize Excel tables.")
|
parser = argparse.ArgumentParser(description="Serialize Excel tables.")
|
||||||
|
|
||||||
parser.add_argument(
|
# Single file mode (optional fallback)
|
||||||
"-i", "--input",
|
parser.add_argument("-i", "--input", help="Input Excel file")
|
||||||
required=True,
|
parser.add_argument("-o", "--output", help="Output Excel file")
|
||||||
help="Input Excel file"
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
# Directory mode
|
||||||
"-o", "--output",
|
parser.add_argument("--input-dir", help="Input directory")
|
||||||
required=True,
|
parser.add_argument("--output-dir", help="Output directory")
|
||||||
help="Output Excel file"
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-t", "--type",
|
"-t", "--type",
|
||||||
@ -31,7 +44,7 @@ def main():
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Select formatter based on type
|
# Select formatter
|
||||||
if args.type == "ring":
|
if args.type == "ring":
|
||||||
formatter = ring_formater
|
formatter = ring_formater
|
||||||
row_instructions = ring_formater.ROW_INSTRUCTIONS
|
row_instructions = ring_formater.ROW_INSTRUCTIONS
|
||||||
@ -39,23 +52,36 @@ def main():
|
|||||||
formatter = countings_formater
|
formatter = countings_formater
|
||||||
row_instructions = countings_formater.ROW_INSTRUCTION
|
row_instructions = countings_formater.ROW_INSTRUCTION
|
||||||
|
|
||||||
logger.info("Reading file, building serializer...")
|
# directory
|
||||||
serializer = TableSerializer(
|
if args.input_dir and args.output_dir:
|
||||||
args.input,
|
logger.info("Running in directory mode")
|
||||||
formatter.EXPECTED_INPUT_TABLE_SCHEMA,
|
|
||||||
formatter.EXPECTED_OUTPUT_TABLE_SCHEMA
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("Starting transformation")
|
for root, _, files in os.walk(args.input_dir):
|
||||||
serializer.run(
|
for file in files:
|
||||||
formatter.COL_INSTRUCTIONS,
|
if not file.endswith((".xlsx", ".xls")):
|
||||||
row_instructions
|
continue
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("Writing transformations")
|
input_path = os.path.join(root, file)
|
||||||
serializer.write_output(args.output)
|
|
||||||
|
# Create corresponding output path
|
||||||
|
relative_path = os.path.relpath(root, args.input_dir)
|
||||||
|
output_root = os.path.join(args.output_dir, relative_path)
|
||||||
|
os.makedirs(output_root, exist_ok=True)
|
||||||
|
|
||||||
|
output_path = os.path.join(output_root, file)
|
||||||
|
|
||||||
|
process_file(input_path, output_path, formatter, row_instructions)
|
||||||
|
|
||||||
|
# single file
|
||||||
|
elif args.input and args.output:
|
||||||
|
logger.info("Running in single file mode")
|
||||||
|
process_file(args.input, args.output, formatter, row_instructions)
|
||||||
|
|
||||||
|
else:
|
||||||
|
parser.error("You must provide either input/output files or input-dir/output-dir")
|
||||||
|
|
||||||
logger.info("Done")
|
logger.info("Done")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
@ -6,6 +6,7 @@ SPICIES = {
|
|||||||
"bbar",
|
"bbar",
|
||||||
"Barbastella",
|
"Barbastella",
|
||||||
"barbastellus",
|
"barbastellus",
|
||||||
|
"Bbararar",
|
||||||
"B.b.",
|
"B.b.",
|
||||||
"B.b",
|
"B.b",
|
||||||
"BB",
|
"BB",
|
||||||
@ -37,6 +38,7 @@ SPICIES = {
|
|||||||
"P.pip.",
|
"P.pip.",
|
||||||
"P.pip",
|
"P.pip",
|
||||||
"PPIP",
|
"PPIP",
|
||||||
|
"P.p."
|
||||||
"ppip",
|
"ppip",
|
||||||
"Pipistrellus pipistrellus",
|
"Pipistrellus pipistrellus",
|
||||||
],
|
],
|
||||||
@ -155,6 +157,7 @@ SPICIES = {
|
|||||||
"P.nat.",
|
"P.nat.",
|
||||||
"P.nat",
|
"P.nat",
|
||||||
"PNAT",
|
"PNAT",
|
||||||
|
"Pnatatat",
|
||||||
"pnat",
|
"pnat",
|
||||||
"Pipistrellus nathusii",
|
"Pipistrellus nathusii",
|
||||||
"P.n.",
|
"P.n.",
|
||||||
@ -177,6 +180,7 @@ SPICIES = {
|
|||||||
"unbekannt",
|
"unbekannt",
|
||||||
"unb.",
|
"unb.",
|
||||||
"Unbestimmt",
|
"Unbestimmt",
|
||||||
|
"Mspecbech"
|
||||||
],
|
],
|
||||||
"Malc": [
|
"Malc": [
|
||||||
"M.alc.",
|
"M.alc.",
|
||||||
@ -227,6 +231,7 @@ SPICIES = {
|
|||||||
"MSPEC",
|
"MSPEC",
|
||||||
"mspec",
|
"mspec",
|
||||||
"Myotis",
|
"Myotis",
|
||||||
|
"Mspec.Mspec",
|
||||||
"M.spe.",
|
"M.spe.",
|
||||||
"M.spe",
|
"M.spe",
|
||||||
"MSPE",
|
"MSPE",
|
||||||
@ -251,6 +256,7 @@ SPICIES = {
|
|||||||
"MMYO",
|
"MMYO",
|
||||||
"mmyo",
|
"mmyo",
|
||||||
"Myotis Myotis",
|
"Myotis Myotis",
|
||||||
|
"Mspec.bech"
|
||||||
"M.m.",
|
"M.m.",
|
||||||
"M.m",
|
"M.m",
|
||||||
"MM",
|
"MM",
|
||||||
|
|||||||
@ -77,7 +77,4 @@ ROW_INSTRUCTIONS = [
|
|||||||
"target": "Wiederfunde",
|
"target": "Wiederfunde",
|
||||||
"value": "TRUE",
|
"value": "TRUE",
|
||||||
}
|
}
|
||||||
#{
|
|
||||||
# "command": "ROW_COPY_REMAINING"
|
|
||||||
#}
|
|
||||||
]
|
]
|
||||||
Loading…
x
Reference in New Issue
Block a user