Skip to content

Commit

Permalink
chore: add linting commands
Browse files Browse the repository at this point in the history
-lint files wherever possible
-add make lint and make format
  • Loading branch information
Maniktherana committed Nov 4, 2023
1 parent 8bd50f2 commit 4603e2d
Show file tree
Hide file tree
Showing 12 changed files with 636 additions and 429 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class

# ruff formatter cache
/.ruff_cache

# C extensions
*.so

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ docker:
dockerRun:
docker run -d --name py-amibot -p 3333:3333 py-amibot

lint:
poetry run ruff check **/*.py

format:
poetry run ruff format **/*.py

.PHONY: gen, mongo, dev, env, docker, dockerRun


Expand Down
4 changes: 4 additions & 0 deletions controllers/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

logger = logging.getLogger()


async def checkToken(telegram_id: int, token: int) -> bool:
try:
logger.info("Checking token")
Expand All @@ -20,6 +21,7 @@ async def checkToken(telegram_id: int, token: int) -> bool:
print(e)
return False


async def setToken(telegram_id: int, token: int) -> bool:
try:
filter = {"_id": telegram_id}
Expand All @@ -30,6 +32,7 @@ async def setToken(telegram_id: int, token: int) -> bool:
logger.error(e)
return False


async def create_profile(telegram_id: int, username, password) -> str:
data = await profile.find_one({"_id": telegram_id})
if data != None:
Expand All @@ -46,6 +49,7 @@ async def create_profile(telegram_id: int, username, password) -> str:
except Exception as e:
return str(e)


async def get_profile_via_token(token: int) -> dict | None:
try:
logger.info("Getting profile")
Expand Down
13 changes: 8 additions & 5 deletions controllers/rpc_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def get_user_profile(telegram_id: int):
finally:
await channel.close()


async def get_class_schedule_profile(profile: dict) -> pb.ScheduledClass | None:
try:
logger.info("Getting schedule")
Expand All @@ -49,18 +50,20 @@ async def get_class_schedule_profile(profile: dict) -> pb.ScheduledClass | None:

logger.info("Getting class schedule via grpc")
response = await stub.GetClassSchedule(
pb.ClassScheduleRequest(date=val),
pb.ClassScheduleRequest(date=val),
metadata=metadata,
)

return response

except Exception as e:
logger.error(e)
return None


async def get_class_schedule(telegram_id: int, tomorrow = False, cal_date='') -> pb.ScheduledClass | None:
async def get_class_schedule(
telegram_id: int, tomorrow=False, cal_date=""
) -> pb.ScheduledClass | None:
profile = await get_profile(telegram_id)
if profile is None:
return None
Expand All @@ -71,10 +74,10 @@ async def get_class_schedule(telegram_id: int, tomorrow = False, cal_date='') ->
today = date.today() + timedelta(days=1)

elif len(cal_date) > 1:
today = datetime.strptime(cal_date, '%Y-%m-%d')
today = datetime.strptime(cal_date, "%Y-%m-%d")

else:
today = date.today()
today = date.today()

val = _date_pb2.Date(year=today.year, month=today.month, day=today.day)

Expand Down
13 changes: 5 additions & 8 deletions formatter/response_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def get_courses_formatter(response: pb.Courses) -> str:

def get_class_schedule_formatter(response: pb.ScheduledClasses) -> str:
logger.info("Formatting")
attendance_indicators = ''

attendance_indicators = ""
msg = "Class Schedule: \n\n"

for index in response.classes:
Expand All @@ -68,13 +68,10 @@ def get_class_schedule_formatter(response: pb.ScheduledClasses) -> str:
msg += f"{start.strftime('%H:%M')} to {end.strftime('%H:%M')} \n"
msg += f"{index.faculty} \n"
indicator = attendance_responder(index.attendance)
msg += (
f"{index.room} \n"
+ f"Attendance : {indicator}"
)
msg += f"{index.room} \n" + f"Attendance : {indicator}"
msg += "\n\n"
attendance_indicators += indicator
return attendance_indicators + '\n' + msg
return attendance_indicators + "\n" + msg


def attendance_responder(val: pb.AttendanceState) -> str:
Expand All @@ -95,4 +92,4 @@ def peaker(classes) -> str:
response = ""
for item in classes:
response += attendance_responder(item.attendance)
return response
return response
220 changes: 129 additions & 91 deletions gen/amizone_pb2.py

Large diffs are not rendered by default.

Loading

0 comments on commit 4603e2d

Please sign in to comment.