-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconvert.py
45 lines (34 loc) · 1.45 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
import glob
import os
import sys
import zipfile
import combine_cup as comb
import convert_cupx as cnv
DATA_DIR: str = 'data'
OUTPUT_DIR: str = 'output'
def unzip() -> None:
all_filenames: list[str] = [i for i in glob.glob('*.zip', root_dir=os.path.join(DATA_DIR, ''))]
print('Input zip file(s):\n', all_filenames)
for fn in all_filenames:
with zipfile.ZipFile(os.path.join(DATA_DIR, fn), 'r') as zip_ref:
zip_ref.extractall(os.path.join(DATA_DIR, ''))
def convert() -> None:
all_filenames: list[str] = [i for i in glob.glob('*.cupx', root_dir=os.path.join(DATA_DIR, ''))]
print('Input cpux file(s):\n', all_filenames)
for fn in all_filenames:
cnv.cpux2xcsoar(os.path.join(DATA_DIR, fn))
def concat_wp_details(file_name) -> None:
all_filenames: list[str] = [i for i in glob.glob('*.txt', root_dir=os.path.join(OUTPUT_DIR, ''))]
print('Input txt file(s):\n', all_filenames)
with open(os.path.join(OUTPUT_DIR, file_name), 'w') as outfile:
for filename in all_filenames:
with open(os.path.join(OUTPUT_DIR, filename)) as infile:
contents = infile.read()
outfile.write(contents)
if __name__ == '__main__':
unzip()
convert()
name: str = sys.argv[1] if len(sys.argv) > 1 else 'landewiesen'
comb.combine('{}.cup'.format(name))
concat_wp_details('{}_details.txt'.format(name))
print('Waypoint details file: {}_details.txt\n'.format(name))