Update data_update.py for removing whitespace in credit ocr result (#441)

* Update data_update.py for removing whitespace in credit ocr result

sometimes ocr provides a str like '1 2261000' and conversion to int int('1 2261000') fails. we do a post process here, removing the whitespace and allow the conversion to be successful

* Update data_update.py for removing whitespace in credit ocr result 

sometimes ocr provides a str like '1 2261000' and conversion to int int('1 2261000') fails. we do a post process here, removing the whitespace and allow the conversion to be successful
edited to align with standards of this repo
This commit is contained in:
Asxcvbn 2024-05-07 12:14:01 +08:00 committed by GitHub
parent aa40215cb8
commit 0f33ba733e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,5 @@
import re
from module.base.timer import Timer
from module.logger import logger
from module.ocr.ocr import Digit
@ -19,7 +21,7 @@ class DataUpdate(UI):
while 1:
data = ocr.detect_and_ocr(self.device.image)
if len(data) == 2:
credit, jade = [int(d.ocr_text) for d in data]
credit, jade = [int(re.sub(r'\s', '', d.ocr_text)) for d in data]
if credit > 0 or jade > 0:
break