Skip to content

Commit a71e848

Browse files
authored
Use custom field separator (#32)
1 parent f6dd358 commit a71e848

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Set these variables either in the environment or a `.env` file along with the sc
1717
7. `FIREFLY_DRY_RUN`: Set this to any value to dry run and skip the firefly API call.
1818
8. `SPLITWISE_DAYS=1`
1919
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.
20+
10. `SPLITWISE_FIELD_SEPARATOR=/`: Set this to something else to use a custom separator in case any of the field values contain a `/`.
2021

2122
## Debt tracking feature
2223
When enabled, tracks Splitwise payable and receivable debts in an account defined by `SW_BALANCE_ACCOUNT`.

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def load_config() -> Config:
3939
"FOREIGN_CURRENCY_TOFIX_TAG": os.getenv("FOREIGN_CURRENCY_TOFIX_TAG"),
4040
"SW_BALANCE_ACCOUNT": os.getenv("SW_BALANCE_ACCOUNT", False),
4141
"SW_BALANCE_DEFAULT_DESCRIPTION": os.getenv("SW_BALANCE_DEFAULT_DESCRIPTION", "Splitwise balance"),
42+
"SPLITWISE_FIELD_SEPARATOR": os.getenv("SPLITWISE_FIELD_SEPARATOR", "/")
4243
}
4344

4445
time_now = datetime.now().astimezone()
@@ -156,7 +157,7 @@ def processText(text: str) -> list[str]:
156157
"""
157158
if not text:
158159
return []
159-
split = text.split("/")
160+
split = text.split(conf["SPLITWISE_FIELD_SEPARATOR"])
160161
if split[0].strip().lower() == "firefly":
161162
return split[1:] or [True]
162163
return []

tests/test_main.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,19 @@ def test_getDate():
7777
assert result.month == 9
7878
assert result.day == 10
7979

80-
@pytest.mark.parametrize("text,expected", [
81-
("firefly/category/description", ["category", "description"]),
82-
("firefly", [True]),
83-
("normal text", []),
80+
@pytest.mark.parametrize("text,expected,separator", [
81+
("firefly/category/description", ["category", "description"], None),
82+
("firefly", [True], None),
83+
("firefly|custom|sep", ["custom", "sep"], "|"),
84+
("firefly,custom/with/slash,sep", ["custom/with/slash", "sep"], ","),
8485
])
85-
def test_processText(text, expected):
86-
processText = load_main().processText
86+
def test_processText(text, expected, separator):
87+
main = load_main()
88+
processText = main.processText
89+
if separator:
90+
main.conf["SPLITWISE_FIELD_SEPARATOR"] = separator
8791
assert processText(text) == expected
92+
main.conf["SPLITWISE_FIELD_SEPARATOR"] = "/"
8893

8994
@patch('requests.request')
9095
def test_callApi(mock_request):

0 commit comments

Comments
 (0)