Skip to content

Commit

Permalink
feat: Allow sync_id as file name.
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanelli committed Jul 21, 2024
1 parent d606ef8 commit 76c2d6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ with Actual(
print(t.date, account_name, t.notes, t.amount, category)
```

The `file` will be matched to either one of the following:

- The name of the budget, found top the top left cornet
- The ID of the budget, a UUID that is only available if you inspect the result of the method `list_user_files`
- The Sync ID of the budget, a UUID available on the frontend on the "Advanced options"
- If none of those options work for you, you can search for the file manually with `list_user_files` and provide the
object directly:

```python
from actual import Actual

with Actual("http://localhost:5006", password="mypass") as actual:
actual.set_file(actual.list_user_files().data[0])
actual.download_budget()
```

## Adding new transactions

After you created your first budget (or when updating an existing budget), you can add new transactions by adding them
Expand Down
9 changes: 6 additions & 3 deletions actual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,19 @@ def session(self) -> Session:
return self._session

def set_file(self, file_id: Union[str, RemoteFileListDTO]) -> RemoteFileListDTO:
"""Sets the file id for the class for further requests. The file_id argument can be either a name or remote
id from the file. If the name is provided, only the first match is taken."""
"""
Sets the file id for the class for further requests. The file_id argument can be either the name, the remote
id or the group id (also known as sync_id) from the file. If there are duplicates for the name, this method
will raise `UnknownFileId`.
"""
if isinstance(file_id, RemoteFileListDTO):
self._file = file_id
return file_id
else:
selected_files = []
user_files = self.list_user_files()
for file in user_files.data:
if (file.file_id == file_id or file.name == file_id) and file.deleted == 0:
if (file.file_id == file_id or file.name == file_id or file.group_id == file_id) and file.deleted == 0:
selected_files.append(file)
if len(selected_files) == 0:
raise UnknownFileId(f"Could not find a file id or identifier '{file_id}'")
Expand Down

0 comments on commit 76c2d6a

Please sign in to comment.