From 43a63232cefc4e5027e4618e4ed2222a106c13cf Mon Sep 17 00:00:00 2001
From: davidh-ssec <david.hoese@ssec.wisc.edu>
Date: Mon, 18 Dec 2017 14:04:54 -0600
Subject: [PATCH] Fix influxdb conversion to tower frame

---
 aosstower/level_00/influxdb.py | 15 ++++++++++-----
 aosstower/level_00/parser.py   |  8 ++++----
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/aosstower/level_00/influxdb.py b/aosstower/level_00/influxdb.py
index 145a964..8ebfe21 100644
--- a/aosstower/level_00/influxdb.py
+++ b/aosstower/level_00/influxdb.py
@@ -52,6 +52,8 @@ def main():
     import argparse
     parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
     parser.add_argument('--logfn', help='Log to rotating file')
+    parser.add_argument('--debug', action='store_true',
+                        help='Don\'t submit records to the database, print them to stdout')
     parser.add_argument('-t', '--tail', action='store_true',
                         help=('Tail file forever, not returning. This will start at the end '
                               'of the file and insert any new data added after starting'))
@@ -92,11 +94,14 @@ def main():
     for idx, record in enumerate(record_gen):
         LOG.info("Inserting records for frame %d", idx)
         record = {symbols[k] or k: v for k, v in record.items() if k in symbols}
-        lines = influxdb.frame_records(record, **station_tags)
-        resp = requests.post(
-            'http://{host}:{port:d}/write?db={dbname}'.format(host=args.host, port=args.port, dbname=args.dbname),
-            data='\n'.join(lines))
-        resp.raise_for_status()
+        if args.debug:
+            print(idx, record)
+        else:
+            lines = influxdb.frame_records(record, **station_tags)
+            resp = requests.post(
+                'http://{host}:{port:d}/write?db={dbname}'.format(host=args.host, port=args.port, dbname=args.dbname),
+                data='\n'.join(lines))
+            resp.raise_for_status()
         if args.sleep_interval:
             time.sleep(args.sleep_interval)
 
diff --git a/aosstower/level_00/parser.py b/aosstower/level_00/parser.py
index 17e8f11..9b2dbb5 100644
--- a/aosstower/level_00/parser.py
+++ b/aosstower/level_00/parser.py
@@ -64,13 +64,13 @@ class LineParseError(Exception):
         raise exc
 
 
-def _make_frame(data):
+def _make_frame(data, rename_timestamp=False):
     """Construct a frame from a list of tuples.
     """
     frame = {}
     for key, value in data:
-        if key == 'stamp':
-            frame[key] = value
+        if key in ['stamp', 'timestamp']:
+            frame['stamp' if rename_timestamp else key] = value
             continue
         if key in database:
             try:
@@ -217,7 +217,7 @@ def read_frames(source, error_handler=lambda *a: None, tail=False):
 
 def loggernet_to_tower(rec_dict):
     """Convert loggernet record dictionary to our standard naming"""
-    return _make_frame(zip(ParserV1V2.names, rec_dict.values()))
+    return _make_frame(zip(ParserV1V2.names, rec_dict.values()), rename_timestamp=True)
 
 
 def ldmp_generator(station_name, tables):
-- 
GitLab