Skip to content

Commit

Permalink
Idk
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelRobitaille committed May 27, 2024
1 parent ed2fc30 commit 9ea6a29
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions process_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_total_advanced(data, text, ocrimg, filename: Path):
def get_total(text: str, *args, **kwargs):
for total in re.finditer(
r'\b(?:tota[li]|kreditkarte|total amount|[mh]astercard)'
r'[\sa-z]*(?:ca[ds]{1,2}|)[\s\$\'§=:]*([0-9\., :]+)',
r'[\sa-z«]*(?:\d[ .]{3,}|)(?:ca[ds]{1,2}|)[\s\$\'§=:]*([0-9\., :]+)',
text,
re.IGNORECASE,
):
Expand Down Expand Up @@ -198,7 +198,7 @@ def get_paid_by(text: str):
last_four_digits: str = env('CARD_LAST_FOUR_DIGITS')
# Eights sometimes come across as B in OCR
last_four_digits = re.sub('[38]', '[38B]', last_four_digits)
if re.search(last_four_digits, text):
if re.search(f'card number.*{last_four_digits}', text, re.IGNORECASE):
return 'Marcel'
return 'Federica'

Expand Down Expand Up @@ -232,6 +232,7 @@ def process_image(filename: Path):
# %%
# TODO
assert str(filename).endswith('.jpg')
print('process_image', filename)

# TODO: It's not really orig anylonger
orig = perspective_transform_by_qr(filename)
Expand Down Expand Up @@ -280,15 +281,14 @@ def process_image(filename: Path):
# output,
# )


receiptCnt = None
receipt = None
# loop over the contours
for i, c in enumerate(cnts):
# approximate the contour
# https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.003 * peri, True)
approx = cv2.approxPolyDP(c, 0.004 * peri, True)
# if our approximated contour has four points, then we can
# assume we have found the outline of the receipt
if len(approx) > 6:
Expand Down Expand Up @@ -394,6 +394,7 @@ def length(line):
paid_by = get_paid_by(text=text)
store = get_store(text=text)

print()
print('Store:', store)
print('Paid by:', paid_by)
print('Date:', date)
Expand Down Expand Up @@ -429,24 +430,12 @@ def length(line):
headers={
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:97.0) '
'Gecko/20100101 Firefox/97.0',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
# 'Accept': 'application/json, text/javascript, */*; q=0.01',
# 'Accept-Language': 'en-US,en;q=0.5',
# 'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://secure.splitwise.com/',
'X-CSRF-Token': env('CSRF_TOKEN'),
# 'Content-Type': 'application/x-www-form-urlencoded',

# 'Content-Type': 'multipart/form-data',
# 'X-Requested-With': 'XMLHttpRequest',
# 'Origin': 'https://secure.splitwise.com',
# 'DNT': '1',
# 'Connection': 'keep-alive',
'Cookie': env('COOKIE'),
# 'Sec-Fetch-Dest': 'empty',
# 'Sec-Fetch-Mode': 'cors',
# 'Sec-Fetch-Site': 'same-origin',
# 'Pragma': 'no-cache',
# 'Cache-Control': 'no-cache',
},
data=data,
files={'receipt':
Expand Down

0 comments on commit 9ea6a29

Please sign in to comment.