-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconvert.py
54 lines (49 loc) · 1.46 KB
/
convert.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
import os
import textwrap
import argparse
from pathlib import Path
from utils.markdown import (
get_df_from_md_document,
clean_md_document,
save_md_table_to_csv,
MD_PATH,
PROJECT_NAME,
)
def _get_parser():
parser = argparse.ArgumentParser(
description=textwrap.dedent(
"""
This script is used to:
- clean up the passed in markdown file,
- export the table in the passed in markdown file to a csv
"""
),
epilog=textwrap.dedent(
"""
# Convert to CSV file
$ python convert.py --to-csv --output data.csv
# Clean up the table in the README file
$ python convert.py --clean-up
"""
),
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--to-csv",
action="store_true",
help="Converts the table in the README to a csv file.",
)
parser.add_argument("--output", help="Name of the output csv.")
parser.add_argument(
"--clean-doc", action="store_true", help="Cleans up the table in the README."
)
args = parser.parse_args()
if args.to_csv and (args.output is None):
parser.error("--to-csv requires --output.")
return args
if __name__ == "__main__":
args = _get_parser()
if args.clean_doc:
clean_md_document(Path(MD_PATH), PROJECT_NAME)
if args.to_csv:
save_md_table_to_csv(Path(MD_PATH), PROJECT_NAME, Path(args.output))