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

Commit a427a1c

Browse files
committed
Removed the redundant data.py file and made a schema for the announcement's author
1 parent 3cd0f0e commit a427a1c

3 files changed

Lines changed: 21 additions & 127 deletions

File tree

netschoolapi/data.py

Lines changed: 0 additions & 110 deletions
This file was deleted.

netschoolapi/netschoolapi.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import httpx
77
from httpx import AsyncClient, Response
88

9-
from netschoolapi import data, errors, schemas
9+
from netschoolapi import errors, schemas
1010

1111
__all__ = ['NetSchoolAPI']
1212

@@ -142,7 +142,7 @@ async def _request_with_optional_relogin(
142142
return response
143143

144144
async def download_attachment(
145-
self, attachment: data.Attachment,
145+
self, attachment: schemas.Attachment,
146146
path_or_file: Union[BytesIO, str] = None,
147147
requests_timeout: int = None):
148148
"""
@@ -167,7 +167,7 @@ async def download_attachment(
167167
file.close()
168168

169169
async def download_attachment_as_bytes(
170-
self, attachment: data.Attachment, requests_timeout: int = None,
170+
self, attachment: schemas.Attachment, requests_timeout: int = None,
171171
) -> BytesIO:
172172
attachment_contents_buffer = BytesIO()
173173
await self.download_attachment(
@@ -181,7 +181,7 @@ async def diary(
181181
start: Optional[date] = None,
182182
end: Optional[date] = None,
183183
requests_timeout: int = None,
184-
) -> data.Diary:
184+
) -> schemas.Diary:
185185
if not start:
186186
monday = date.today() - timedelta(days=date.today().weekday())
187187
start = monday
@@ -200,14 +200,14 @@ async def diary(
200200
)
201201
diary_schema = schemas.Diary()
202202
diary_schema.context['assignment_types'] = self._assignment_types
203-
return data.diary(diary_schema.load(response.json()))
203+
return diary_schema.load(response.json())
204204

205205
async def overdue(
206206
self,
207207
start: Optional[date] = None,
208208
end: Optional[date] = None,
209209
requests_timeout: int = None,
210-
) -> List[data.Assignment]:
210+
) -> List[schemas.Assignment]:
211211
if not start:
212212
monday = date.today() - timedelta(days=date.today().weekday())
213213
start = monday
@@ -227,25 +227,22 @@ async def overdue(
227227
assignments_schema = schemas.Assignment()
228228
assignments_schema.context['assignment_types'] = self._assignment_types
229229
assignments = assignments_schema.load(response.json(), many=True)
230-
return [data.Assignment(**assignment) for assignment in assignments]
230+
return assignments
231231

232232
async def announcements(
233233
self, take: Optional[int] = -1,
234-
requests_timeout: int = None) -> List[data.Announcement]:
234+
requests_timeout: int = None) -> List[schemas.Announcement]:
235235
response = await self._request_with_optional_relogin(
236236
requests_timeout,
237237
'announcements',
238238
params={'take': take},
239239
)
240240
announcements = schemas.Announcement().load(response.json(), many=True)
241-
return [
242-
data.announcement(announcement)
243-
for announcement in announcements
244-
]
241+
return announcements
245242

246243
async def attachments(
247-
self, assignment: data.Assignment,
248-
requests_timeout: int = None) -> List[data.Attachment]:
244+
self, assignment: schemas.Assignment,
245+
requests_timeout: int = None) -> List[schemas.Attachment]:
249246
response = await self._request_with_optional_relogin(
250247
requests_timeout,
251248
method="POST",
@@ -258,15 +255,15 @@ async def attachments(
258255
return []
259256
attachments_json = response[0]['attachments']
260257
attachments = schemas.Attachment().load(attachments_json, many=True)
261-
return [data.Attachment(**attachment) for attachment in attachments]
258+
return attachments
262259

263-
async def school(self, requests_timeout: int = None):
260+
async def school(self, requests_timeout: int = None) -> schemas.School:
264261
response = await self._request_with_optional_relogin(
265262
requests_timeout,
266263
'schools/{0}/card'.format(self._school_id),
267264
)
268265
school = schemas.School().load(response.json())
269-
return data.School(**school)
266+
return school
270267

271268
async def logout(self, requests_timeout: int = None):
272269
try:

netschoolapi/schemas.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ class Attachment(NetSchoolAPISchema):
1717
description = fields.String(allow_none=True, missing='')
1818

1919

20+
class Author(NetSchoolAPISchema):
21+
id = fields.Integer()
22+
full_name = fields.String(data_key="fio")
23+
nickname = fields.String(data_key="nickName")
24+
25+
2026
class Announcement(NetSchoolAPISchema):
2127
name = fields.String()
2228
content = fields.String(data_key='description')
2329
post_date = fields.DateTime(data_key='postDate')
2430
attachments = fields.List(fields.Nested(Attachment), missing=[])
31+
author = fields.Nested(Author)
2532

2633

2734
class Assignment(NetSchoolAPISchema):

0 commit comments

Comments
 (0)