Skip to content
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Commit f41de67

Browse files
committed
Referencing stuff by ID wherever possible
1 parent a427a1c commit f41de67

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

netschoolapi/netschoolapi.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,10 @@ async def _request_with_optional_relogin(
142142
return response
143143

144144
async def download_attachment(
145-
self, attachment: schemas.Attachment,
146-
path_or_file: Union[BytesIO, str] = None,
145+
self, attachment_id: int,
146+
path_or_file: Union[BytesIO, str],
147147
requests_timeout: int = None):
148-
"""
149-
If `path_to_file` is a string, it should contain absolute path to file
150-
"""
151-
if path_or_file is None:
152-
file = open(attachment.name, "wb")
153-
file_is_new = True
154-
elif isinstance(path_or_file, str):
148+
if isinstance(path_or_file, str):
155149
file = open(path_or_file, "wb")
156150
file_is_new = True
157151
else:
@@ -160,18 +154,18 @@ async def download_attachment(
160154
file.write((
161155
await self._request_with_optional_relogin(
162156
requests_timeout,
163-
f"attachments/{attachment.id}",
157+
f"attachments/{attachment_id}",
164158
)
165159
).content)
166160
if file_is_new:
167161
file.close()
168162

169163
async def download_attachment_as_bytes(
170-
self, attachment: schemas.Attachment, requests_timeout: int = None,
164+
self, attachment_id: int, requests_timeout: int = None,
171165
) -> BytesIO:
172166
attachment_contents_buffer = BytesIO()
173167
await self.download_attachment(
174-
attachment, path_or_file=attachment_contents_buffer,
168+
attachment_id, path_or_file=attachment_contents_buffer,
175169
requests_timeout=requests_timeout
176170
)
177171
return attachment_contents_buffer
@@ -241,14 +235,14 @@ async def announcements(
241235
return announcements
242236

243237
async def attachments(
244-
self, assignment: schemas.Assignment,
238+
self, assignment_id: int,
245239
requests_timeout: int = None) -> List[schemas.Attachment]:
246240
response = await self._request_with_optional_relogin(
247241
requests_timeout,
248242
method="POST",
249243
path='student/diary/get-attachments',
250244
params={'studentId': self._student_id},
251-
json={'assignId': [assignment.id]},
245+
json={'assignId': [assignment_id]},
252246
)
253247
response = response.json()
254248
if not response:

0 commit comments

Comments
 (0)