Skip to content

Commit

Permalink
whisper-update takes values from stdin (#318) (#319)
Browse files Browse the repository at this point in the history
- also mention this in --help text

(cherry picked from commit 3ce395e)

Co-authored-by: rowlap <[email protected]>
  • Loading branch information
deniszh and rowlap authored Jan 6, 2022
1 parent ed5ff81 commit 8827cc9
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 8827cc9

Please sign in to comment.