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
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