drone-rigide/doc/compte_rendu/scripts/parse_topic.py
2019-06-07 15:29:39 +02:00

35 lines
966 B
Python

#! /usr/bin/python3
import yaml
import sys
import time
import click
@click.command()
@click.option('--output', default="output.csv", help='Output file')
@click.option('--time/--no-time', 'use_time', default=False, help='Add the number of seconds')
@click.option('--field', default="data", help='YAML field to store')
def main(output, use_time, field):
with open(output, 'w') as f:
s = ""
last_line = ""
try:
for line in sys.stdin:
if line == "---\n":
v = yaml.load(s)[field]
print(v)
if use_time:
f.write(str(time.time()) + ',' + str(v) + "\n")
else:
f.write(str(v)+"\n")
s = ""
else:
s += line + '\n'
except KeyboardInterrupt:
print("Output saved to " + output)
if __name__ == '__main__':
main()