]> www.average.org Git - loctrkd.git/commitdiff
qry: initial support for saving data in a file
authorEugene Crosser <crosser@average.org>
Fri, 15 Jul 2022 14:06:48 +0000 (16:06 +0200)
committerEugene Crosser <crosser@average.org>
Fri, 15 Jul 2022 14:06:48 +0000 (16:06 +0200)
loctrkd/qry.py

index e33ba16b1fcb9d5208de77ae611ea441f01e2ffb..650830e5fc4c57d90ff113ae42a5bcbeefa9ff18 100644 (file)
@@ -43,6 +43,13 @@ def main(
     else:
         proto = ""
         selector = ""
+    dopts = dict(opts)
+    if len(args) > 1 and "-o" in dopts:
+        attr = args[1]
+        fn = dopts["-o"]
+    else:
+        attr = ""
+        fn = ""
 
     c.execute(
         """select tstamp, imei, peeraddr, is_incoming, proto, packet
@@ -64,8 +71,11 @@ def main(
             peeraddr,
             msg,
         )
+        if fn and hasattr(msg, attr):
+            with open(fn, "wb") as fl:  # TODO support multiple files
+                fl.write(getattr(msg, attr))
 
 
 if __name__.endswith("__main__"):
-    opts, args = getopt(argv[1:], "c:d")
+    opts, args = getopt(argv[1:], "o:c:d")
     main(common.init(log, opts=opts), opts, args)