Skip to content

Commit 9446502

Browse files
authored
Merge pull request #1 from perfectra1n/dev
Add quite a few features, including endpoints, not creating logfiles...
2 parents 7b66fc2 + 74778ed commit 9446502

File tree

8 files changed

+119
-54
lines changed

8 files changed

+119
-54
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "PyTrilium"
7-
version = "1.0.7"
7+
version = "1.1.0"
88
authors = [
99
{ name="perfectra1n", email="[email protected]" },
1010
]

pytrilium/PyTrilium.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
from .PyTriliumNoteClient import PyTriliumNoteClient
2-
from .PyTriliumBranchClient import PyTriliumBranchClient
3-
from .PyTriliumAttributeClient import PyTriliumAttributeClient
4-
from .PyTriliumCalendarClient import PyTriliumCalendarClient
1+
from .PyTriliumCustomClient import PyTriliumCustomClient
52

6-
class PyTrilium(PyTriliumNoteClient, PyTriliumBranchClient, PyTriliumAttributeClient, PyTriliumCalendarClient):
3+
class PyTrilium(PyTriliumCustomClient):
74
def __init__(self, url, token=None, password=None, debug=False) -> None:
85
"""Initializes the PyTrilium class. You need to either provide an ETAPI token OR a password (which will then be used to generate an ETAPI token).
96

pytrilium/PyTriliumAttributeClient.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def get_attribute_by_id(self, attribute_id: str) -> dict:
1616
1717
Returns
1818
-------
19-
requests.Response
19+
dict
2020
The response from the Trilium API.
2121
"""
2222
return self.make_request(f"/attributes/{attribute_id}").json()
2323

24-
def post_attribute(self, data: str) -> requests.Response:
24+
def post_attribute(self, data: str) -> dict:
2525
"""This will create a new Attribute.
2626
2727
Parameters
@@ -31,7 +31,7 @@ def post_attribute(self, data: str) -> requests.Response:
3131
3232
Returns
3333
-------
34-
requests.Response
35-
The response from the Trilium API.
34+
dict
35+
The JSON response from Trilium, as a dictionary.
3636
"""
37-
return self.make_request("/attributes", method="POST", data=data)
37+
return self.make_request("/attributes", method="POST", data=data).json()

pytrilium/PyTriliumBranchClient.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def get_branch_by_id(self, branch_id: str) -> dict:
1616
1717
Returns
1818
-------
19-
requests.Response
19+
dict
2020
The response from the Trilium API.
2121
"""
2222
return self.make_request(f"/branches/{branch_id}").json()
2323

24-
def post_branch(self, data: str) -> requests.Response:
24+
def post_branch(self, data: str) -> dict:
2525
"""This will create a new Branch.
2626
2727
Parameters
@@ -31,12 +31,12 @@ def post_branch(self, data: str) -> requests.Response:
3131
3232
Returns
3333
-------
34-
requests.Response
34+
dict
3535
The response from the Trilium API.
3636
"""
3737
return self.make_request("/branches", method="POST", data=data)
3838

39-
def patch_branch_by_id(self, branch_id: str, data: str) -> requests.Response:
39+
def patch_branch_by_id(self, branch_id: str, data: str) -> dict:
4040
"""Given the Branch's ID, this will update the Branch's information.
4141
4242
Parameters
@@ -48,12 +48,12 @@ def patch_branch_by_id(self, branch_id: str, data: str) -> requests.Response:
4848
4949
Returns
5050
-------
51-
requests.Response
52-
The response from the Trilium API.
51+
dict
52+
The JSON response from Trilium, as a dictionary.
5353
"""
5454
return self.make_request(f"/branches/{branch_id}", method="PATCH", data=data)
5555

56-
def delete_branch_by_id(self, branch_id: str) -> requests.Response:
56+
def delete_branch_by_id(self, branch_id: str) -> dict:
5757
"""Given the Branch's ID, this will delete the Branch.
5858
5959
Parameters
@@ -63,7 +63,7 @@ def delete_branch_by_id(self, branch_id: str) -> requests.Response:
6363
6464
Returns
6565
-------
66-
requests.Response
67-
The response from the Trilium API.
66+
dict
67+
The JSON response from Trilium, as a dictionary.
6868
"""
6969
return self.make_request(f"/branches/{branch_id}", method="DELETE")

pytrilium/PyTriliumCalendarClient.py

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,62 @@ class PyTriliumCalendarClient(PyTriliumClient):
66
def __init__(self, url, token, debug=False) -> None:
77
super().__init__(url, token, debug)
88

9-
def get_year_note(self, year: str) -> requests.Response:
10-
return self.make_request(f"calendar/years/{year}")
9+
def get_year_note(self, year: str) -> dict:
10+
"""Get the note for a year, in Trilium's calendar.
1111
12-
def get_weeks_note(self, weeks: str) -> requests.Response:
13-
return self.make_request(f"calendar/weeks/{weeks}")
12+
Parameters
13+
----------
14+
year : str
15+
The year you want to fetch from Trilium's calendar.
16+
17+
Returns
18+
-------
19+
dict
20+
The JSON response from Trilium, as a dictionary.
21+
"""
22+
return self.make_request(f"calendar/years/{year}").json()
23+
24+
def get_weeks_note(self, weeks: str) -> dict:
25+
"""Get the note for a week, in Trilium's calendar.
26+
27+
Parameters
28+
----------
29+
weeks : str
30+
The week you want to fetch from Trilium's calendar.
31+
32+
Returns
33+
-------
34+
dict
35+
The JSON response from Trilium, as a dictionary.
36+
"""
37+
return self.make_request(f"calendar/weeks/{weeks}").json()
1438

15-
def get_months_note(self, months: str) -> requests.Response:
16-
return self.make_request(f"calendar/months/{months}")
39+
def get_months_note(self, months: str) -> dict:
40+
"""Get the note for a month, in Trilium's calendar.
41+
42+
Parameters
43+
----------
44+
months : str
45+
The month you want to fetch from Trilium's calendar.
46+
47+
Returns
48+
-------
49+
dict
50+
The JSON response from Trilium, as a dictionary.
51+
"""
52+
return self.make_request(f"calendar/months/{months}").json()
1753

18-
def get_days_note(self, date: str) -> requests.Response:
19-
return self.make_request(f"calendar/days/{date}")
54+
def get_days_note(self, date: str) -> dict:
55+
"""Get the note for a day, in Trilium's calendar.
56+
57+
Parameters
58+
----------
59+
date : str
60+
The date you want to fetch from Trilium's calendar.
61+
62+
Returns
63+
-------
64+
dict
65+
The JSON response from Trilium, as a dictionary.
66+
"""
67+
return self.make_request(f"calendar/days/{date}").json()

pytrilium/PyTriliumClient.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, url: str, token: str, debug: bool = False) -> None:
3535
logger_name="PyTriliumClient",
3636
log_file_name="PyTriliumClient.log",
3737
debug=debug,
38-
create_log_file=True,
38+
create_log_file=False,
3939
)
4040

4141
# The valid response codes that can come from Triliu
@@ -125,3 +125,13 @@ def attempt_basic_call(self) -> None:
125125
raise ValueError(
126126
f"Invalid response code: {str(resp.status_code)}, response text: {resp.text}. Response code should be one of {self.valid_response_codes}. Please check your Trilium, URL, and token."
127127
)
128+
129+
def get_app_info(self) -> dict:
130+
"""Gets the app info from the Trilium API.
131+
132+
Returns
133+
-------
134+
dict
135+
The app info from the Trilium API.
136+
"""
137+
return self.make_request("/app-info").json()

pytrilium/PyTriliumCustomClient.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from .PyTriliumNoteClient import PyTriliumNoteClient
2+
from .PyTriliumBranchClient import PyTriliumBranchClient
3+
from .PyTriliumAttributeClient import PyTriliumAttributeClient
4+
from .PyTriliumCalendarClient import PyTriliumCalendarClient
5+
6+
# This class inherits from everything else, but also implements custom functions
7+
# so I'm creating this to help save my sanity in the future
8+
class PyTriliumCustomClient(PyTriliumNoteClient, PyTriliumBranchClient, PyTriliumAttributeClient, PyTriliumCalendarClient):
9+
def __init__(self, url, token, debug=False) -> None:
10+
super().__init__(url, token, debug)

pytrilium/PyTriliumNoteClient.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def get_note_by_id(self, note_id: str) -> dict:
1616
1717
Returns
1818
-------
19-
requests.Response
20-
The response from the Trilium API.
19+
dict
20+
The JSON response from Trilium, as a dictionary.
2121
"""
2222
return self.make_request(f"/notes/{note_id}").json()
2323

@@ -36,7 +36,7 @@ def get_note_content_by_id(self, note_id: str) -> str:
3636
"""
3737
return self.make_request(f"/notes/{note_id}/content").text
3838

39-
def put_note_content_by_id(self, note_id: str, data: str) -> requests.Response:
39+
def put_note_content_by_id(self, note_id: str, data: str) -> dict:
4040
"""Given the Note's ID, this will update the Note's content.
4141
4242
Parameters
@@ -48,12 +48,12 @@ def put_note_content_by_id(self, note_id: str, data: str) -> requests.Response:
4848
4949
Returns
5050
-------
51-
requests.Response
52-
The response from the Trilium API.
51+
dict
52+
The JSON response from Trilium, as a dictionary.
5353
"""
54-
return self.make_request(f"/notes/{note_id}/content", method="PUT", data=data)
54+
return self.make_request(f"/notes/{note_id}/content", method="PUT", data=data).json()
5555

56-
def patch_note_by_id(self, note_id: str, data: str) -> requests.Response:
56+
def patch_note_by_id(self, note_id: str, data: str) -> dict:
5757
"""Given the Note's ID, this will update the Note's content.
5858
5959
Parameters
@@ -65,12 +65,12 @@ def patch_note_by_id(self, note_id: str, data: str) -> requests.Response:
6565
6666
Returns
6767
-------
68-
requests.Response
69-
The response from the Trilium API.
68+
dict
69+
The JSON response from Trilium, as a dictionary.
7070
"""
71-
return self.make_request(f"/notes/{note_id}", method="PATCH", data=data)
71+
return self.make_request(f"/notes/{note_id}", method="PATCH", data=data).json()
7272

73-
def delete_note_by_id(self, note_id: str) -> requests.Response:
73+
def delete_note_by_id(self, note_id: str) -> dict:
7474
"""Given the Note's ID, this will delete the Note.
7575
7676
Parameters
@@ -80,10 +80,10 @@ def delete_note_by_id(self, note_id: str) -> requests.Response:
8080
8181
Returns
8282
-------
83-
requests.Response
84-
The response from the Trilium API.
83+
dict
84+
The JSON response from Trilium, as a dictionary.
8585
"""
86-
return self.make_request(f"/notes/{note_id}", method="DELETE")
86+
return self.make_request(f"/notes/{note_id}", method="DELETE").json()
8787

8888
def export_note_by_id(self, note_id: str, filepath_to_save_export_zip: str, format="html") -> bool:
8989
"""Given the Note's ID, export itself and all child notes into a singular .zip archive.
@@ -123,7 +123,7 @@ def export_note_by_id(self, note_id: str, filepath_to_save_export_zip: str, form
123123
return False
124124
return True
125125

126-
def create_note_revision(self, note_id: str, data: str, format: str = "html") -> requests.Response:
126+
def create_note_revision(self, note_id: str, data: str, format: str = "html") -> dict:
127127
"""Given the Note's ID, create a new revision of the Note.
128128
129129
Parameters
@@ -137,14 +137,14 @@ def create_note_revision(self, note_id: str, data: str, format: str = "html") ->
137137
138138
Returns
139139
-------
140-
requests.Response
141-
The response from the Trilium API.
140+
dict
141+
The JSON response from Trilium, as a dictionary.
142142
"""
143143

144144
params = {"format": format}
145-
return self.make_request(f"/notes/{note_id}/note-revision", method="POST", data=data, params=params)
145+
return self.make_request(f"/notes/{note_id}/note-revision", method="POST", data=data, params=params).json()
146146

147-
def refresh_note_ordering(self, parent_note_id: str) -> requests.Response:
147+
def refresh_note_ordering(self, parent_note_id: str) -> dict:
148148
"""Given the Note's ID, refresh the node ordering of the Note.
149149
150150
Parameters
@@ -154,12 +154,12 @@ def refresh_note_ordering(self, parent_note_id: str) -> requests.Response:
154154
155155
Returns
156156
-------
157-
requests.Response
158-
The response from the Trilium API.
157+
dict
158+
The JSON response from Trilium, as a dictionary.
159159
"""
160160
return self.make_request(f"/refresh-note-ordering/{parent_note_id}", method="POST")
161161

162-
def create_note(self, data: str) -> requests.Response:
162+
def create_note(self, data: str) -> dict:
163163
"""Create a new Note.
164164
165165
Parameters
@@ -169,7 +169,7 @@ def create_note(self, data: str) -> requests.Response:
169169
170170
Returns
171171
-------
172-
requests.Response
173-
The response from the Trilium API.
172+
dict
173+
The JSON response from Trilium, as a dictionary.
174174
"""
175-
return self.make_request("/create-note", method="POST", data=data)
175+
return self.make_request("/create-note", method="POST", data=data).json()

0 commit comments

Comments
 (0)