Skip to content

Commit 241a2a2

Browse files
feat: problem filter, add edit command
1 parent acb4fd3 commit 241a2a2

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/commands/edit.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import typer
2+
3+
from src.server.solution_manager import SolutionManager
4+
from src.server.auth import Auth
5+
from commands.test import map_lang
6+
7+
solution_manager = SolutionManager(Auth().get_session())
8+
9+
def edit(
10+
problem: str = typer.Argument(..., help="Problem name or id."),
11+
lang: str = typer.Argument("cpp", help="Programming language to use."),
12+
editor: str = typer.Option("code", '-e', help="Code editor to use."),
13+
):
14+
"""Solves a problem by passing lang param and open it with your code editor."""
15+
question_data = solution_manager.get_question_data(problem).get('data', {}).get('question')
16+
17+
if not question_data:
18+
typer.echo(f"Problem {problem} not found.")
19+
return
20+
21+
def create_file_with_template(lang: str):
22+
with open(f"{question_data.get('titleSlug')}.{lang}", "w") as f:
23+
for snippet in question_data.get('codeSnippets', []):
24+
if snippet.get('langSlug').lower() == map_lang.get(lang):
25+
f.write(snippet.get('code'))
26+
return
27+
typer.echo(f"No template found for language {lang}")
28+
29+
create_file_with_template(lang)
30+
31+
import subprocess
32+
subprocess.run([editor, f"{question_data.get('titleSlug')}.{lang}"])

src/commands/list_problems.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
def list_problems(
2121
difficulty: Optional[str] = typer.Option(None, "--difficulty", "-d", help="Filter by difficulty (easy/medium/hard)"),
22-
status: Optional[str] = typer.Option(None, "--status", "-s", help="Filter by status (todo/in-progress/done)"),
22+
status: Optional[str] = typer.Option(None, "--status", "-s", help="Filter by status (todo/attempted/solved)"),
2323
tag: Optional[str] = typer.Option(None, "--tag", "-t", help="Filter by tags (comma-separated)"),
2424
category_slug: Optional[str] = typer.Option("all-code-essentials", "--category-slug", "-c", help="Filter by category slug")
2525
):

src/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import profile
22
import typer
33
from src import show, profile
4+
from src.commands.edit import edit
45
from src.commands.list_problems import list_problems
56
from src.commands.login import login, logout
67
from src.commands.submit import submit
@@ -15,6 +16,7 @@
1516
app.command(name="logout")(logout)
1617
app.command(name="submit")(submit)
1718
app.command(name="test")(test)
19+
app.command(name="edit")(edit)
1820

1921
if __name__ == "__main__":
2022
app()

src/server/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def fetch_problem_list(
6060
skip: int = 0,
6161
filters: dict = {}
6262
):
63+
if filters and 'difficulty' in filters:
64+
filters['difficulty'] = filters['difficulty'].upper()
65+
6366
client = create_leetcode_client(csrf_token, session_id)
6467
variables = {
6568
"categorySlug": categorySlug,

0 commit comments

Comments
 (0)