add unified logger
authormilaq <micha.laqua@gmail.com>
Sun, 25 May 2014 13:11:36 +0000 (15:11 +0200)
committerTamber Penketh <tamber@furryhelix.co.uk>
Wed, 6 Jun 2018 22:38:25 +0000 (23:38 +0100)
 * create logs directory if not exists
 * generic names

obd_recorder.py

index db30d44..c91cffb 100755 (executable)
@@ -6,6 +6,7 @@ import platform
 import obd_sensors
 from datetime import datetime
 import time
+import os
 
 from obd_utils import scanSerial
 
@@ -15,8 +16,9 @@ class OBD_Recorder():
         self.port = None
         self.sensorlist = []
         localtime = time.localtime(time.time())
-        filename = path + "bike-" + str(localtime[0]) + "-" + str(localtime[1]) + "-" + str(
-            localtime[2]) + "-" + str(localtime[3]) + "-" + str(localtime[4]) + "-" + str(localtime[5]) + ".log"
+        filename = path + str(localtime[0]) + "-" + str(localtime[1]) + "-" +
+        str(localtime[2]) + "_" + str(localtime[3]) + "-" + str(localtime[4]) +
+        "-" + str(localtime[5]) + ".log"
         self.log_file = open(filename, "w", 128)
         self.log_file.write("Time,RPM,MPH,Throttle,Load,Gear\n")
 
@@ -97,7 +99,10 @@ class OBD_Recorder():
 
 
 logitems = ["rpm", "speed", "throttle_pos", "load"]
-o = OBD_Recorder('/home/pi/logs/', logitems)
+d = "logs"
+if not os.path.exists(d):
+    os.makedirs(d)
+o = OBD_Recorder('logs/', logitems)
 o.connect()
 if not o.is_connected():
     print "Not connected"