Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Set these variables either in the environment or a `.env` file along with the sc
7. `FIREFLY_DRY_RUN`: Set this to any value to dry run and skip the firefly API call.
8. `SPLITWISE_DAYS=1`
9. `SW_BALANCE_ACCOUNT=Splitwise balance`: Set this to the name of the virtual Splitwise balance asset account on Firefly to enable the debt tracking feature.
10. `SPLITWISE_FIELD_SEPARATOR=/`: Set this to something else to use a custom separator in case any of the field values contain a `/`.

## Debt tracking feature
When enabled, tracks Splitwise payable and receivable debts in an account defined by `SW_BALANCE_ACCOUNT`.
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def load_config() -> Config:
"FOREIGN_CURRENCY_TOFIX_TAG": os.getenv("FOREIGN_CURRENCY_TOFIX_TAG"),
"SW_BALANCE_ACCOUNT": os.getenv("SW_BALANCE_ACCOUNT", False),
"SW_BALANCE_DEFAULT_DESCRIPTION": os.getenv("SW_BALANCE_DEFAULT_DESCRIPTION", "Splitwise balance"),
"SPLITWISE_FIELD_SEPARATOR": os.getenv("SPLITWISE_FIELD_SEPARATOR", "/")
}

time_now = datetime.now().astimezone()
Expand Down Expand Up @@ -156,7 +157,7 @@ def processText(text: str) -> list[str]:
"""
if not text:
return []
split = text.split("/")
split = text.split(conf["SPLITWISE_FIELD_SEPARATOR"])
if split[0].strip().lower() == "firefly":
return split[1:] or [True]
return []
Expand Down
17 changes: 11 additions & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ def test_getDate():
assert result.month == 9
assert result.day == 10

@pytest.mark.parametrize("text,expected", [
("firefly/category/description", ["category", "description"]),
("firefly", [True]),
("normal text", []),
@pytest.mark.parametrize("text,expected,separator", [
("firefly/category/description", ["category", "description"], None),
("firefly", [True], None),
("firefly|custom|sep", ["custom", "sep"], "|"),
("firefly,custom/with/slash,sep", ["custom/with/slash", "sep"], ","),
])
def test_processText(text, expected):
processText = load_main().processText
def test_processText(text, expected, separator):
main = load_main()
processText = main.processText
if separator:
main.conf["SPLITWISE_FIELD_SEPARATOR"] = separator
assert processText(text) == expected
main.conf["SPLITWISE_FIELD_SEPARATOR"] = "/"

@patch('requests.request')
def test_callApi(mock_request):
Expand Down