Skip to content

adding leetcode functionality#1

Open
ishanpr wants to merge 12 commits intoscippage:mainfrom
ishanpr:main
Open

adding leetcode functionality#1
ishanpr wants to merge 12 commits intoscippage:mainfrom
ishanpr:main

Conversation

@ishanpr
Copy link

@ishanpr ishanpr commented Sep 20, 2023

  • Added /leetcode command that sends a random leetcode problem with a difficulty you specify
  • Added /leetcode-subscribe that pairs you up with another person that chose the same day of the week (same choices as /subscribe), and the same difficulty you specified.
  • Created LeetCodeDB in db.py to carry out the above.
  • Updated /schedule so that it would show the leetcode schedule as well
  • Updated /unsubscribe so that it would unsubscribe from leetcode-subscribe as well as display the updated Leetcode schedule.

-Updated the /leetcode-subscribe command
NOTE: This function still doesn't work as intended

ishanpr and others added 7 commits September 19, 2023 00:24
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
@Yaxe1 Yaxe1 requested review from Yaxe1 and scippage September 20, 2023 07:25
Copy link
Owner

@scippage scippage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract these constants

raise error


async def distribute_any_users(difficulty_users_dict, any_users):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use LeetcodeDifficulty



async def distribute_any_users(difficulty_users_dict, any_users):
# First, ensure all bins have an even number of users
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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", [])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract all "magic strings" to constants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants