Skip to content

Commit

Permalink
fix crash when no date is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
davye committed Oct 18, 2024
1 parent 24f8bfa commit c3beb2e
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions source/backend/resource/resource_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,42 @@ def receipts_parsing():
"sep": "09", "oct": "10", "nov": "11", "dec": "12"}
splitList = []

# 09/12/2024
if "/" in inputDate:
splitList = inputDate.split("/")

# 09-12-2024
elif "-" in inputDate:
splitList = inputDate.split("-")

# Sep 12, 2024
elif inputDate[0:3].lower() in months:
splitList = inputDate.split(" ")

try:
month = months[splitList[0][0:3].lower()]
except:
month = splitList[0]
day = splitList[1]
year = splitList[2]

if len(year) == 2:
year = "20" + year
if len(month) == 1:
month = "0" + month
if "," in day:
day = day[:-1]
if len(day) == 1:
day = "0" + day

assert int(month) >= 1 and int(month) <= 12
assert int(day) >= 1 and int(day) <= 31
assert int(year) >= 2000 and int(year) < 2100

outputDate = year + "-" + month + "-" + day
if inputDate is not None:
# 09/12/2024
if "/" in inputDate:
splitList = inputDate.split("/")

# 09-12-2024
elif "-" in inputDate:
splitList = inputDate.split("-")

# Sep 12, 2024
elif inputDate[0:3].lower() in months:
splitList = inputDate.split(" ")

try:
month = months[splitList[0][0:3].lower()]
except:
month = splitList[0]
day = splitList[1]
year = splitList[2]

if len(year) == 2:
year = "20" + year
if len(month) == 1:
month = "0" + month
if "," in day:
day = day[:-1]
if len(day) == 1:
day = "0" + day

assert int(month) >= 1 and int(month) <= 12
assert int(day) >= 1 and int(day) <= 31
assert int(year) >= 2000 and int(year) < 2100

outputDate = year + "-" + month + "-" + day
else:
outputDate = datetime.now().strftime("%Y-%m-%d")
output = {
'receipt_date': outputDate,
'total': result['amazon']['extracted_data'][0]['payment_information']['amount_due'],
Expand Down

0 comments on commit c3beb2e

Please sign in to comment.