This repository has been archived by the owner on Apr 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract.py
executable file
·78 lines (56 loc) · 2.36 KB
/
extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
"""Parse labels extracted from herbarium specimens."""
import sys
import argparse
import textwrap
from digi_leap.pylib.util import __VERSION__
from digi_leap.readers import csv_reader
# Date, taxon names, collector, collector number
# admin units: like state, county, country
# scientificName for the binomial and genus and species separately
INPUT_FORMATS = {
'csv': csv_reader}
OUTPUT_FORMATS = {}
def parse_traits(args):
"""Perform actions based on the arguments."""
reader = INPUT_FORMATS[args.input_format]
reader.read(args)
def parse_args():
"""Process command-line arguments."""
description = """Download data from the eFloras website."""
arg_parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent(description),
fromfile_prefix_chars='@')
arg_parser.add_argument(
'--version', '-V', action='version',
version='%(prog)s v{}'.format(__VERSION__))
arg_parser.add_argument(
'--trait', '-t', default='',
help="""The traits to extract.""")
arg_parser.add_argument(
'--search-field', '-s', action='append', metavar='FIELD',
help=f"""A field that contains the data to parse. You may use this
argument more than once.""")
arg_parser.add_argument(
'--extra-field', '-e', action='append', metavar='FIELD',
help="""An extra field to to append to an output row. You may use this
argument more than once.""")
arg_parser.add_argument(
'--input-file', '-i', type=argparse.FileType(), default=sys.stdin,
help="""The input file containing the raw data. Defaults to stdin.""")
arg_parser.add_argument(
'--input-format', '-I', default='csv',
choices=INPUT_FORMATS.keys(),
help="""The data input format. The default is "csv".""")
arg_parser.add_argument(
'--output-file', '-o', type=argparse.FileType('w'), default=sys.stdout,
help="""Output the results to this file. Defaults to stdout.""")
arg_parser.add_argument(
'--output-format', '-O', default='csv', choices=OUTPUT_FORMATS.keys(),
help="""Output the result in this format. The default is "csv".""")
args = arg_parser.parse_args()
return args
if __name__ == "__main__":
ARGS = parse_args()
parse_traits(ARGS)