Skip to content

Commit

Permalink
whisper-update takes values from stdin (#318)
Browse files Browse the repository at this point in the history
- also mention this in --help text
  • Loading branch information
rowlap authored Jun 20, 2021
1 parent d13c9f4 commit 3ce395e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bin/whisper-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@
now = int(time.time())

option_parser = optparse.OptionParser(
usage='''%prog [options] path timestamp:value [timestamp:value]*''')
usage='''%prog [options] path [timestamp:value]*
If no values are passed as arguments, they are read one-per-line from stdin.''')

(options, args) = option_parser.parse_args()

if len(args) < 2:
if not args:
option_parser.print_help()
sys.exit(1)

path = args[0]
datapoint_strings = args[1:]
if len(args) >= 2:
datapoint_strings = args[1:]
else:
# no argv values, so read from stdin
datapoint_strings = sys.stdin
datapoint_strings = [point.replace('N:', '%d:' % now)
for point in datapoint_strings]
datapoints = [tuple(point.split(':')) for point in datapoint_strings]
Expand Down

0 comments on commit 3ce395e

Please sign in to comment.