#! /usr/bin/python3 import yaml import sys import time import click @click.command() @click.option('--output', default="output.csv", help='Number of greetings.') @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()