Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash when no date is detected #117

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading