-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from KarimullinArthur/devolop
V0.0.5
- Loading branch information
Showing
10 changed files
with
542 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from .bonchapi import * | ||
from .parser import * | ||
from .__meta__ import __version__ | ||
from .bonchapi import BonchAPI | ||
from .schemas import Lesson |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from dataclasses import dataclass | ||
import datetime | ||
|
||
from . import validator | ||
|
||
|
||
@dataclass() | ||
class Lesson(validator.Validations): | ||
date: str | ||
day: str | ||
number: int | ||
time: str | ||
subject: str | ||
lesson_type: str | ||
location: str | ||
teacher: str | ||
|
||
def date_to_datetime(self): | ||
self.date = datetime.datetime.strptime(self.date, "%Y-%m-%d") | ||
|
||
def validate_number(self, value, **_) -> int: | ||
if isinstance(value, str): | ||
value = int(value) | ||
return value | ||
|
||
def __iter__(self): | ||
# return self | ||
return iter([self.date, self.day, self.number, self.time, self.subject, self.lesson_type, self.location, self.teacher]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Validations: | ||
def __post_init__(self): | ||
"""Run validation methods if declared. | ||
The validation method can be a simple check | ||
that raises ValueError or a transformation to | ||
the field value. | ||
The validation is performed by calling a function named: | ||
`validate_<field_name>(self, value, field) -> field.type` | ||
""" | ||
for name, field in self.__dataclass_fields__.items(): | ||
if (method := getattr(self, f"validate_{name}", None)): | ||
setattr(self, name, method(getattr(self, name), field=field)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import asyncio | ||
import argparse | ||
import os | ||
|
||
from bonchapi import BonchAPI | ||
|
||
import dotenv | ||
|
||
|
||
dotenv.load_dotenv(dotenv_path="./examples/autoclick/.env") | ||
|
||
|
||
parser = argparse.ArgumentParser( | ||
prog="bonchcli", | ||
description='What the program does', | ||
epilog='Text at the bottom of help') | ||
|
||
parser.add_argument('week_offset', nargs="?", type=int, default=0) | ||
args = parser.parse_args() | ||
|
||
|
||
async def main(): | ||
api = BonchAPI() | ||
|
||
api.cookies = {} | ||
|
||
mail = str(os.environ.get("mail")) | ||
password = str(os.environ.get("password")) | ||
|
||
await api.login(mail, password) | ||
|
||
rsp = await api.get_timetable(week_offset=args.week_offset) | ||
|
||
week: list[str] = [] | ||
state = True | ||
firstly = True | ||
count = 0 | ||
|
||
for lesson in rsp: | ||
try: | ||
if week[-1] != lesson.date: | ||
week.append(lesson.date) | ||
except IndexError: | ||
week.append(lesson.date) | ||
|
||
for lesson in rsp: | ||
if firstly: | ||
firstly = False | ||
state = True | ||
elif lesson.date == week[count]: | ||
state = False | ||
else: | ||
print("╚", "─"*32, sep="") | ||
state = True | ||
count += 1 | ||
|
||
for arg in lesson: | ||
if arg == lesson.date and state: | ||
print("\t", "\x1b[93;1m", arg, "\x1b[0m") | ||
# print("\t", arg, "\x1b[0m") | ||
elif arg == lesson.day and state: | ||
print("\t", arg, "\n") | ||
elif arg in (lesson.date, lesson.day) and state == False: | ||
pass | ||
elif arg == lesson.number: | ||
if arg is not None: | ||
print("\x1b[93;41m", arg, "\x1b[0m", end='') | ||
else: | ||
print("╔", "─", sep="", end='') | ||
elif arg == lesson.time: | ||
if state: | ||
end = "─"*12 | ||
else: | ||
end = '' | ||
print("─"*4, "\x1b[93;5m",arg, "\x1b[0m", "─"*4, end, sep="") | ||
|
||
elif arg == lesson.lesson_type: | ||
if lesson.lesson_type == "Лекция": | ||
color = "\x1b[94;5m" | ||
elif lesson.lesson_type == "Практические занятия": | ||
color = "\x1b[92;5m" | ||
elif lesson.lesson_type == "Лабораторная работа": | ||
color = "\x1b[91;5m" | ||
elif lesson.lesson_type == "Консультация": | ||
color = "\x1b[95;5m" | ||
elif lesson.lesson_type in ("Экзамен", "Зачет"): | ||
color = "🕱 \x1b[91;5m" | ||
else: | ||
color = "\x1b[94;5m" | ||
print("│ ", color, arg, "\x1b[0m", sep="") | ||
|
||
elif arg == lesson.teacher: | ||
print("│ ", "\x1b[77;1m", arg, "\x1b[0m", sep="") | ||
else: | ||
print('│', arg) | ||
|
||
|
||
print("╚", "─"*32, sep="") | ||
|
||
asyncio.run(main()) |
Oops, something went wrong.