database recording
database recording

file:a/scannr.py -> file:b/scannr.py
--- a/scannr.py
+++ b/scannr.py
@@ -11,6 +11,7 @@
 import serial
 #python -m serial.tools.miniterm -p COM20 -e -b 115200 --cr
 import psycopg2
+import csv
 import sys,os
 
 
@@ -19,10 +20,9 @@
 
 filename = "demo.wav"
 MIN_LENGTH = 90000
-nma = pynma.PyNMA( "apikey(s)", "developerkey")    
-conn = psycopg2.connect("dbname=test user=postgres")
 
-def worker(filename):
+
+def worker(filename, length):
 
     """thread worker function
     http://www.doughellmann.com/PyMOTW/threading/
@@ -34,12 +34,23 @@
     ser.write("GLG\r")   
     line = ser.readline()   # read a '\n' terminated line
     print line
-    """nma.push(application, event, description, (opt) url,)"""
-    """http://initd.org/psycopg/docs/usage.html"""
-    #cur = conn.cursor()
-    #cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, "abc'def"))
-    #conn.commit()
-    #cur.close()
+    reader = csv.reader([line])
+    for row in reader:
+        #GLG,40078,NFM,0,0,CanberraBlackMnt,AustralianCapita,SES Ops 1,1,0,NONE,NONE,NONE
+        if (row[0] != 'GLG'):
+            print "uh oh"
+        if (row[1] != ''):  
+            tgid = row[1]
+            #nma.push("scannr", "ping", filename, "http://www.google.com")
+            tgname = row[7]
+            sitename = row[5]
+            """http://initd.org/psycopg/docs/usage.html"""
+            cur = conn.cursor()
+            cur.execute("INSERT INTO recordings (filename,tgid,tgname,sitename,length) VALUES (%s, %s,%s, %s, %s)",(filename,tgid,tgname,sitename, length))
+            conn.commit()
+            cur.close()
+        else:
+            print filename+" has no TGID"
 
     return
 
@@ -54,7 +65,7 @@
     if len(data) > MIN_LENGTH:
         data = snd.pack('<' + ('h'*len(data)), *data)
         path = filename
-        dispatcher.send( signal='FILE_CREATED', sender=filename, filename=filename)
+        dispatcher.send( signal='FILE_CREATED', sender=filename, filename=filename, length=len(data))
         wf = wave.open(path, 'wb')
         wf.setnchannels(1)
         wf.setsampwidth(sample_width)
@@ -66,10 +77,14 @@
 dispatcher.connect( filenameMaker, signal='SND_STARTED', sender=dispatcher.Any )
 dispatcher.connect( worker, signal='FILE_CREATED', sender=dispatcher.Any )
 
+print "Opening serial port..."
 ser = serial.Serial('COM20', 112500, timeout=1) 
-
-print "Scannr started..."
+print "Loading notifymyandroid..."
+nma = pynma.PyNMA( "a6f50f76119eda33befe4325b4b9e1dd25eef7bad2868e4f")    
+print "Connecting database..."
+conn = psycopg2.connect("dbname=scannr user=postgres password=snmc")
+print "Scannr started."
 while True:
-    print "ready to record"
+    print "ready to record again"
     record_to_async_file()
 ser.close()