summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-01-15 14:24:46 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-01-15 14:24:46 +0100
commit1e0da90e7b0806f7ec175c6d60b78938dd7a1634 (patch)
treeb218e1aefbce7b3c3387ef7c186ece3f818edac9
parentFetch the device information in all commands. (diff)
downloadglucometerutils-1e0da90e7b0806f7ec175c6d60b78938dd7a1634.tar
glucometerutils-1e0da90e7b0806f7ec175c6d60b78938dd7a1634.tar.gz
glucometerutils-1e0da90e7b0806f7ec175c6d60b78938dd7a1634.tar.bz2
glucometerutils-1e0da90e7b0806f7ec175c6d60b78938dd7a1634.tar.lz
glucometerutils-1e0da90e7b0806f7ec175c6d60b78938dd7a1634.tar.xz
glucometerutils-1e0da90e7b0806f7ec175c6d60b78938dd7a1634.tar.zst
glucometerutils-1e0da90e7b0806f7ec175c6d60b78938dd7a1634.zip
-rwxr-xr-xglucometer.py4
-rw-r--r--glucometerutils/common.py6
2 files changed, 7 insertions, 3 deletions
diff --git a/glucometer.py b/glucometer.py
index 8e19237..148daff 100755
--- a/glucometer.py
+++ b/glucometer.py
@@ -76,9 +76,7 @@ def main():
readings, key=lambda reading: getattr(reading, args.sort_by))
for reading in readings:
- print('"%s","%.2f","%s","%s"' % (
- reading.timestamp, reading.get_value_as(unit),
- reading.meal, reading.comment))
+ print(reading.as_csv(unit))
elif args.action == 'datetime':
if args.set == 'now':
print(device.set_datetime())
diff --git a/glucometerutils/common.py b/glucometerutils/common.py
index 1e7e7f8..ac5c931 100644
--- a/glucometerutils/common.py
+++ b/glucometerutils/common.py
@@ -84,6 +84,12 @@ class Reading(_ReadingBase):
"""
return convert_glucose_unit(self.value, UNIT_MGDL, to_unit)
+ def as_csv(self, unit):
+ """Returns the reading as a formatted comma-separated value string."""
+ return '"%s","%.2f","%s","%s"' % (
+ self.timestamp, self.get_value_as(unit), self.meal, self.comment)
+
+
_MeterInfoBase = collections.namedtuple(
'_MeterInfoBase', ['model', 'serial_number', 'version_info', 'native_unit'])