Try to reduce runaway memory usaqe
Try to reduce runaway memory usaqe

file:b/.gitmodules (new)
--- /dev/null
+++ b/.gitmodules
@@ -1,1 +1,4 @@
+[submodule "pynma"]
+	path = pynma
+	url = git://github.com/uskr/pynma.git
 

directory:b/pynma (new)
--- /dev/null
+++ b/pynma

file:b/run.bat (new)
--- /dev/null
+++ b/run.bat
@@ -1,1 +1,1 @@
-
+python scannr.py > output.txt

file:a/scannr.py -> file:b/scannr.py
--- a/scannr.py
+++ b/scannr.py
@@ -10,11 +10,20 @@
 import wave
 import serial
 #python -m serial.tools.miniterm -p COM20 -e -b 115200 --cr
+import psycopg2
+import csv
+import sys,os
+
+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__) or '.', 'pynma'))
+import pynma
 
 filename = "demo.wav"
 MIN_LENGTH = 90000
 
-def worker(filename):
+
+def worker(filename, length):
+
     """thread worker function
     http://www.doughellmann.com/PyMOTW/threading/
     https://github.com/uskr/pynma
@@ -25,6 +34,24 @@
     ser.write("GLG\r")   
     line = ser.readline()   # read a '\n' terminated line
     print line
+    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
 
 def filenameMaker():
@@ -38,22 +65,28 @@
     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)
         wf.setframerate(snd.RATE)
         wf.writeframes(data)
         wf.close()
+        del wf
         print("done - result "+str(len(data))+" frames written to "+path)
+    del data
 
 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()

file:a/snd.py -> file:b/snd.py
--- a/snd.py
+++ b/snd.py
@@ -90,7 +90,6 @@
         data = stream.read(CHUNK_SIZE)
         L = unpack('<' + ('h'*(len(data)/2)), data) # little endian, signed short
         L = array('h', L)
-        LRtn.extend(L)
 
         silent = is_silent(L)
         #print silent, num_silent, L[:10]
@@ -102,6 +101,8 @@
             dispatcher.send( signal='SND_STARTED')
             snd_started = True
             print snd_started
+        if snd_started:
+            LRtn.extend(L)
         if snd_started and num_silent > MAX_SILENT:
             break
 
@@ -127,6 +128,7 @@
     wf.writeframes(data)
     wf.close()
     print("done - result written to "+path)
+    del data