Conversation
Added /leetcode-subscribe which allows users to subscribe for leetcode problems for the days already made available by timeblock. Added LeetCodeDB to db.py Error checking code in utils.py
Added Leetcode
There was a problem hiding this comment.
Thanks for working on this! I think this PR might be missing some code. What happened to the bot.run_pairing changes for actually sending out the leetcode pairings (saw it in an earlier commit)? Also, how are you testing your changes?
Could you also run black and isort?
pip install black isort
black . && isort .
You can configure your IDE to do this automatically on save, e.g. for VSCode
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
https://marketplace.visualstudio.com/items?itemName=ms-python.isort
| def generate_schedule(timeblocks: List["Timeblock"]) -> str: | ||
| return f"{[str(block) for block in sorted(timeblocks, key=lambda block: block.value)]}" | ||
|
|
||
| def generate_leetcode_schedule(tuples: List[tuple]) -> str: |
There was a problem hiding this comment.
This should be a @staticmethod like generate_schedule.
An alternate better way would be to a class to represent the concept of a "leetcode schedule entry" (with components Timeblock and LeetcodeDifficulty) and then move this method into that class.
|
|
||
|
|
||
| @tree.command( | ||
| name="leetcode-subscribe", |
There was a problem hiding this comment.
We should probably rename the APIs /subscribe -> /subscribe-pairing and /leetcode-subscribe -> /subscribe-leetcode for consistency. Whatever name you use for "pairing" should be the same as the flag used in the /unsubscribe command (you currently have it as "Programming").
API changes are annoying for users so better to get it right early.
Added distribute_any_users function Created enum class for difficulties
| ): | ||
| try: | ||
| if subscription in ["Programming", "All"]: | ||
| if subscription in ["pairing-subscribe", "All"]: |
| raise error | ||
|
|
||
|
|
||
| async def distribute_any_users(difficulty_users_dict, any_users): |
There was a problem hiding this comment.
add type hints, also this doesn't need to be async
|
|
||
| async def distribute_any_users(difficulty_users_dict, any_users): | ||
| # First, ensure all bins have an even number of users | ||
| for difficulty in ["Easy", "Medium", "Hard"]: |
|
|
||
|
|
||
| async def distribute_any_users(difficulty_users_dict, any_users): | ||
| # First, ensure all bins have an even number of users |
There was a problem hiding this comment.
this doesn't seem right because the random distribution afterwards can just make them all odd again. I think you just want to upgrade size-1 bins up to size-2.
| difficulty=difficulty, | ||
| # Fetch all leetcode subscribers for the timeblock | ||
| all_leetcode_users = {} | ||
| with closing(leetcode_db.con.cursor()) as cur: |
There was a problem hiding this comment.
this should be a function in db.py. we shouldn't directly interact with sqlite in this file.
| all_leetcode_users[difficulty] = [] | ||
| all_leetcode_users[difficulty].append(client.get_user(user_id)) | ||
|
|
||
| any_users = all_leetcode_users.get("Any Difficulty", []) |
There was a problem hiding this comment.
extract all "magic strings" to constants
-Updated the /leetcode-subscribe command
NOTE: This function still doesn't work as intended