Skip to content

Commit

Permalink
fix: Use new Parsers() class instead of the old files
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Jun 15, 2024
1 parent 3647f12 commit 3f7b94d
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions osm_fieldwork/odk2osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
from osm_fieldwork.convert import Convert
from osm_fieldwork.ODKInstance import ODKInstance
from osm_fieldwork.support import OutSupport
from osm_fieldwork.jsondump import JsonDump
from osm_fieldwork.csvdump import CSVDump
from osm_fieldwork.parsers import ODKParsers

# Instantiate logger
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -60,51 +59,41 @@ def main():
)

toplevel = Path(args.infile)
odk = ODKParsers(args.yaml)
odk.parseXLS(args.xlsfile)
out = OutSupport()
xmlfiles = list()
convert = Convert()
data = list()
# It's a wildcard, used for XML instance files
if args.infile.find("*") >= 0:
log.debug(f"Parsing multiple ODK XML files {args.infile}")
toplevel = Path(args.infile[:-1])
for dirs in glob.glob(args.infile):
xml = os.listdir(dirs)
# There ilineagelineages always only one XML file per infile
full = os.path.join(dirs, xml[0])
xmlfiles.append(full)
for infile in xmlfiles:
logging.info(f"Processing infile {infile}")
odk = ODKInstance(infile)
entry = convert.createEntry(odk.data)
tmp = odk.XMLparser(infile)
entry = odk.createEntry(tmp[0])
data.append(entry)
elif toplevel.suffix == '.xml':
# It's an instance file from ODK Collect
log.debug(f"Parsing ODK XML files {args.infile}")
# There is always only one XML file per infile
full = os.path.join(toplevel, os.path.basename(toplevel))
xmlfiles.append(full + ".xml")
odk = ODKInstance(args.infile)
entry = convert.createEntry(odk.data)
tmp = odk.XMLparser(args.infile)
# odki = ODKInstance(filespec=args.infile, yaml=args.yaml)
entry = odk.createEntry(tmp)
data.append(entry)
elif toplevel.suffix == ".csv":
log.debug(f"Parsing csv files {args.infile}")
if args.yaml:
csvin = CSVDump(args.yaml)
else:
csvin = CSVDump()
csvin.parseXLS(args.xlsfile)
for entry in csvin.parse(args.infile):
data.append(convert.createEntry(entry))
for entry in odk.CSVparser(args.infile):
data.append(odk.createEntry(entry))
elif toplevel.suffix == ".json":
log.debug(f"Parsing json files {args.infile}")
if args.yaml:
jsonin = JsonDump(args.yaml)
else:
jsonin = JsonDump()
jsonin.parseXLS(args.xlsfile)
for entry in jsonin.parse(args.infile):
data.append(convert.createEntry(entry))
for entry in odk.JSONparser(args.infile):
data.append(odk.createEntry(entry))

# Write the data
out.WriteData(toplevel.stem, data)
Expand Down

0 comments on commit 3f7b94d

Please sign in to comment.