forked from K-Phoen/python-fitparse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfitdump
More file actions
executable file
·82 lines (64 loc) · 2.27 KB
/
fitdump
File metadata and controls
executable file
·82 lines (64 loc) · 2.27 KB
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
79
80
81
82
#!/usr/bin/env python
import argparse
import sys
import fitparse
def format_message(message, options):
s = message.name
if options.with_defs:
s += ' [%s]' % message.type
s += '\n'
if message.type == 'data':
for field_data in message:
s += ' * %s: %s' % (field_data.name, field_data.value)
if field_data.units:
s += ' [%s]' % field_data.units
s += '\n'
return s
def parse_args(args=None):
parser = argparse.ArgumentParser(
description='Dump .FIT files to various formats',
epilog='python-fitparse version %s' % fitparse.__version__,
)
parser.add_argument('-v', '--verbose', action='count', default=0)
parser.add_argument(
'-o', '--output', type=argparse.FileType(mode='wb'),
help='File to output to.',
)
parser.add_argument(
'-t', '--type', choices=('csv', 'excel', 'readable'), default='readable',
help='File type to output. (DEFAULT: %(default)s)',
)
parser.add_argument(
'-n', '--name', help='Message name (or number) to filter',
)
parser.add_argument(
'infile', metavar='FITFILE', type=argparse.FileType(mode='rb'),
help='Input .FIT file (Use - for stdin)',
)
options = parser.parse_args(args)
if (options.type != 'readable') and not options.output:
parser.error('Please specify an output file (-o) or set --type readable')
options.with_defs = (options.verbose >= 1)
options.print_messages = (options.type == 'readable')
options.print_stream = (options.output or sys.stdout)
if not options.print_messages and (options.verbose >= 1):
options.print_messages = True
options.print_stream = sys.stdout
return options
def main(args=None):
options = parse_args(args)
fitfile = fitparse.FitFile(
options.infile,
data_processor=fitparse.StandardUnitsDataProcessor(),
)
messages = fitfile.get_messages(
name=options.name,
with_definitions=options.with_defs,
)
for n, message in enumerate(messages, 1):
if options.print_messages:
print >> options.print_stream, '%d. %s' % (
n, format_message(message, options),
)
if __name__ == '__main__':
main()