I didn't write documentation for the readme yet. If you like the patch, I'll add it.
I noticed too late that I didn't turn off autopep8 in my editor. This PR as it is now includes PEP8-ing your existing code, which isn't a huge change, but mainly some line breaking and whitespace stuff. If you don't like that, I'll remove it again - but I thought maybe you don't have a problem with it, so I don't have to manually change it back. ;-)
Now for the actual change: For my daily use, the functionality the current mappings provide is not sufficient. That's because my bank has one large "description" field which contains payee, description, sometimes the payee's payment info, and a reference number. What I need is a set of regular expressions that dissect the various formats that this field can come in and set payee, comment, tags etc. accordingly.
I thought about extending the current mappings file, but that didn't feel like the best solution for two reasons:
What I need is complex. The simple syntax of the mapping file would be challenged to capture that complexity.
The mapping file is written to by the script. A file that contains such complex rules should probably only be manually edited.
So, I added another "regexp file", which is expected to be in JSON format. From the documentation of the read_regex_file function:
The regex file is a json file, consisting of a list of objects, each object containing:
one regular expression
against what to match this expression
the action to be taken when the regular expression matches
The syntax of an entry in the file is:
{"trigger":
{"where": <index of the column against which to match>,
"regex": "<regular expression>",
"search": true/false (if true, use re.search, otherwise use re.match)},
"action": {…}
}
There are currently four different possible actions:
{"type": "set-payee",
"value": "<new payee>"}
{"type": "set-tag",
"value": "<which tag to set>"}
{"type": "set-account",
"value": "<which account to set>"}
{"type": "set-addon",
"name": "<name of the addon field>",
"value": "<value to set>"}
If the regular expression contains any named groups, those named groups will be used to format the strings given for value. Thus, an entry like:
{"trigger":
{"where": 2,
"regex": "The payee is (?<payee>.*)"},
"action":
{"type": "set-payee",
"value": "{payee}"}
}
would set the payee of any transaction that has the string The payee is somebody
in the second column to somebody.
Hi,
first things first:
autopep8
in my editor. This PR as it is now includes PEP8-ing your existing code, which isn't a huge change, but mainly some line breaking and whitespace stuff. If you don't like that, I'll remove it again - but I thought maybe you don't have a problem with it, so I don't have to manually change it back. ;-)Now for the actual change: For my daily use, the functionality the current mappings provide is not sufficient. That's because my bank has one large "description" field which contains payee, description, sometimes the payee's payment info, and a reference number. What I need is a set of regular expressions that dissect the various formats that this field can come in and set payee, comment, tags etc. accordingly.
I thought about extending the current mappings file, but that didn't feel like the best solution for two reasons:
So, I added another "regexp file", which is expected to be in JSON format. From the documentation of the
read_regex_file
function:The regex file is a json file, consisting of a list of objects, each object containing:
The syntax of an entry in the file is:
There are currently four different possible actions:
If the regular expression contains any named groups, those named groups will be used to format the strings given for value. Thus, an entry like:
would set the payee of any transaction that has the string
The payee is somebody
in the second column tosomebody
.