Provides a data model from a bank export in PDF format.
Operation
Bases: BaseModel
Represents a single bank operation parsed from a PDF statement.
| Attributes: |
|
|---|
weekday
property
weekday: int
Return the ISO weekday number for the operation's date.
Use this property to determine the day of the week according to the ISO standard, where Monday is 1 and Sunday is 7.
| Returns: |
|
|---|
Example
from datetime import date
op = Operation(date=date(2024, 3, 12), time="14:22", category="Coffee", sum=100.0, remains=12345.67)
print(op.weekday)
#> 2 # Tuesday
parse_date
Parse a string into a date object using the format 'DD.MM.YYYY'.
Use this validator to convert a string representation of a date into a Python date object before model initialization.
| Parameters: |
|
|---|
| Returns: |
|---|
| Raises: |
|
|---|
Example
print(cls.parse_date("12.03.2024"))
#> datetime.date(2024, 3, 12)
print(cls.parse_date("invalid-date"))
#> Traceback (most recent call last):
#> ...
#> ValueError: time data 'invalid-date' does not match format '%d.%m.%Y'
from_match
classmethod
Create an Operation instance from a regex match object.
Use this class method to construct an Operation object from a regular expression match with named groups.
| Parameters: |
|---|
| Returns: |
|
|---|
Example
import re
line = "12.03.2024 14:22 456789 КАФЕ +100.00 12345.67"
pattern = r"(?P<date>\d{2}\.\d{2}\.\d{4})\W(?P<time>\d{2}\:\d{2})\W(\d+)\W(?P<category>\D+)\W(?P<sum>\S+)\W(?P<remains>\S+)"
match = re.match(pattern, line)
operation = Operation.from_match(match=match, is_income=True)
print(operation.sum)
#> 100.0