diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-08-04 00:24:59 +0200 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-08-04 00:24:59 +0200 |
commit | 8b1199c17dada74d177e182e4f79b77dfed26673 (patch) | |
tree | fe4448c4a8ac6a704f1462a6e290d834959b3b23 /glucometer.py | |
parent | setup.py: update license specification. (diff) | |
download | glucometerutils-8b1199c17dada74d177e182e4f79b77dfed26673.tar glucometerutils-8b1199c17dada74d177e182e4f79b77dfed26673.tar.gz glucometerutils-8b1199c17dada74d177e182e4f79b77dfed26673.tar.bz2 glucometerutils-8b1199c17dada74d177e182e4f79b77dfed26673.tar.lz glucometerutils-8b1199c17dada74d177e182e4f79b77dfed26673.tar.xz glucometerutils-8b1199c17dada74d177e182e4f79b77dfed26673.tar.zst glucometerutils-8b1199c17dada74d177e182e4f79b77dfed26673.zip |
Diffstat (limited to 'glucometer.py')
-rwxr-xr-x | glucometer.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/glucometer.py b/glucometer.py index 20128ec..c2504f2 100755 --- a/glucometer.py +++ b/glucometer.py @@ -9,6 +9,9 @@ __license__ = 'MIT' import argparse import importlib +import sys + +from dateutil import parser as date_parser from glucometerutils import common from glucometerutils.drivers import otultra2 @@ -33,7 +36,7 @@ def main(): parser_date = subparsers.add_parser( 'datetime', help='Reads or sets the date and time of the glucometer.') parser_date.add_argument( - '--set', action='store_true', + '--set', action='store', nargs='?', const='now', default=None, help='Set the date rather than just reading it from the device.') args = parser.parse_args() @@ -45,8 +48,13 @@ def main(): for reading in device.get_readings(args.unit): print('%s,%f' % reading) elif args.action == 'datetime': - if args.set: + if args.set == 'now': print(device.set_datetime()) + elif args.set: + try: + print(device.set_datetime(date_parser.parse(args.set))) + except ValueError: + print('%s: not a valid date' % args.set, file=sys.stderr) else: print(device.get_datetime()) else: |