-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccsv.py
44 lines (31 loc) · 1.04 KB
/
ccsv.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
import csv
import sys
from pathlib import Path
import click
sys.path.append(Path(__file__).parent)
import parse_tools as ptools
def compute_ccsv(fpath):
'''
Compute and output a single ccsv file
Inputs:
- fpath (str or Path)
'''
csv_lines, tags = ptools.file_splitter(fpath)
computed_lines = ptools.compute_lines(csv_lines)
new_path = Path(fpath).resolve().with_suffix('.csv')
with open(new_path, 'w', encoding='utf-8') as wfile:
writer = csv.writer(wfile)
writer.writerows(computed_lines)
print(f"Created file at {fpath}")
@click.command()
@click.argument('infiles', nargs=-1, type=click.Path(exists=True))
@click.option('-f', '--force', is_flag=True, default=False)
def main(infiles, force):
'''
Compute a list of .ccsv file. For each file in INFILES, compute and output <filename>.ccsv -> <filename>.csv
'''
import pdb;pdb.set_trace()
for fpath in infiles:
compute_ccsv(fpath)
if __name__ == '__main__':
main()