Skip to content

Commit

Permalink
Merge pull request #13 from KarimullinArthur/develop
Browse files Browse the repository at this point in the history
v0.0.6 | Offset Fix
  • Loading branch information
KarimullinArthur authored Feb 13, 2025
2 parents b5ba855 + 4aaf53d commit 5a23223
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ async def main():
api = BonchAPI()
await api.login("YourMail", "YourPassword")
await api.click_start_lesson() # автокликалка на парах
await api.get_timetable() # красивая моделька расписания

asyncio.run(main())
```

---

[BonchCLI](https://github.com/KarimullinArthur/BonchCLI) - клиент lk.sut.ru для красноглазиков
19 changes: 18 additions & 1 deletion bonchapi/bonchapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,28 @@ async def get_raw_timetable(self, week_number: int = False) -> str:
await self.login(self.mail, self.password)
await self.get_raw_timetable(week_number)
return await resp.text()

async def find_first_week_id(self) -> int:
'''
Получение ID первой учебной недели в *семестре*
'''
MAX_WEEK = 50

for i in (0,-1,-2,1,2):
id = MAX_WEEK//2+i
guess = await parser.get_week(await self.get_raw_timetable(id))
if guess == 0:
return id
return 0

async def get_timetable(self, week_number: int = False, *, week_offset: int = False) -> List[schemas.Lesson]:
if week_offset:

if not hasattr(self, "_first_week"):
self._first_week = await self.find_first_week_id()

current_week = await parser.get_week(await self.get_raw_timetable(week_number))
desired_week = current_week + week_offset
desired_week = current_week + week_offset + self._first_week
return await parser.get_my_lessons(await self.get_raw_timetable(desired_week))

else:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "bonchapi"
version = "0.0.5"
version = "0.0.6"
description = 'API client for lk.sut.ru'
readme = "README.md"
requires-python = ">=3.8"
Expand Down

0 comments on commit 5a23223

Please sign in to comment.