Ignore GOCR error message when image is empty master
authorJean-Michel Nirgal Vourgère <jmv_deb@nirgal.com>
Mon, 2 Oct 2017 16:43:25 +0000 (18:43 +0200)
committerJean-Michel Nirgal Vourgère <jmv_deb@nirgal.com>
Mon, 2 Oct 2017 16:43:25 +0000 (18:43 +0200)
go.py

diff --git a/go.py b/go.py
index 9b589a9709c3b0b2f4146912c1b8f4e0ef1304ae..efd7cc2cf9ffb08471835efeba46041f2341ce0e 100755 (executable)
--- a/go.py
+++ b/go.py
@@ -18,6 +18,9 @@ WSOST_PREFIX = '/wsost/OstBrokerWeb/loginform?imgid='
 LOCAL_DIR = '/home/nirgal/banquepostale/'
 CSV_HEADER = 'Date;Libellé;Montant(EUROS);Montant(FRANCS)'
 
+# Message returned by gocr when given an empty blue image:
+EMPTY_GOCR_MSG = 'NOT NORMAL, thresholdValue = 160\n# thresholdValue out of range 0..47, reset to 24\n# no boxes found - stopped\n'
+
 def get_login_password():
     config=open(LOCAL_DIR + 'config').read()
     login=None
@@ -91,10 +94,13 @@ def download():
         proc_convert=Popen('convert loginform.gif -crop 60x60+%s+%s pnm:-' % (column*64, row*64),
             shell=True, stdout=PIPE)
         proc_gocr=Popen('gocr -C 0-9 -i -',
-            shell=True, stdin=proc_convert.stdout, stdout=PIPE)
-        output = proc_gocr.communicate()[0]
+            shell=True, stdin=proc_convert.stdout, stdout=PIPE, stderr=PIPE)
+        output, errmsg = proc_gocr.communicate()
         output = output.decode('utf-8')
         output = output.strip()
+        errmsg = errmsg.decode('utf-8')
+        if errmsg and errmsg != EMPTY_GOCR_MSG:
+            logging.warning('gocr reports error on column %s, row %s: %s', column, row, errmsg)
         #print("choice #%s is %s" % (choice, output))
         xlt_password[output] = choice
     #for i in 0 1 2 3 4 5 6 7 8 9; do convert $i.gif -crop 20x20+5+5 pnm:- | gocr -C 0-9 -i -; done