Skip to content

Commit 58c3cfe

Browse files
fix: problem display using frontendId instead of questionid
1 parent e2f81c1 commit 58c3cfe

File tree

7 files changed

+24
-14
lines changed

7 files changed

+24
-14
lines changed

2529.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution {
2+
public:
3+
int maximumCount(vector<int>& nums) {
4+
5+
}
6+
};

src/commands/daily.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
def daily(
66
lang: str = typer.Argument("py", help="Programming language to use."),
7-
editor: str = typer.Option("vim", '-e', help="Code editor to use."),
7+
editor: str = typer.Option("vim", '--editor', '-e', help="Code editor to use."),
8+
save: bool = typer.Option(False, "--save", "-s", help="Save problem description to a file"),
89
no_editor: bool = typer.Option(False, "--no-editor", help="Skip opening editor"),
910
):
1011
"""
@@ -28,7 +29,7 @@ def daily(
2829
typer.echo("\n" + typer.style(f"❌ Failed to fetch daily question: {str(e)}", fg=typer.colors.RED))
2930
raise typer.Exit(1)
3031

31-
show(problem=question['question']['titleSlug'])
32+
show(problem=question['question']['titleSlug'], save=save)
3233

3334
if not no_editor and editor:
3435
try:

src/commands/edit.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ def edit(
1818
typer.echo(f"Problem {problem} not found.")
1919
return
2020

21+
filename_prefix = question_data.get('questionFrontendId') or (
22+
problem if problem.isdigit() else question_data.get('questionId')
23+
)
24+
2125
def create_file_with_template(lang: str):
22-
with open(f"{question_data.get('titleSlug')}.{lang}", "w") as f:
26+
filename = f"{filename_prefix}.{lang}"
27+
with open(filename, "w") as f:
2328
for snippet in question_data.get('codeSnippets', []):
2429
if snippet.get('langSlug').lower() == map_lang.get(lang):
2530
f.write(snippet.get('code'))
@@ -29,4 +34,4 @@ def create_file_with_template(lang: str):
2934
create_file_with_template(lang)
3035

3136
import subprocess
32-
subprocess.run([editor, f"{question_data.get('titleSlug')}.{lang}"])
37+
subprocess.run([editor, f"{filename_prefix}.{lang}"])

src/commands/show.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import typer
22
import os
3-
from rich.console import Console
43
from ..lib.problem_ui import ProblemDetails
54
from ..server.auth import Auth
65
from ..server.solution_manager import SolutionManager
76

87
auth_manager = Auth()
98
solution_manager = SolutionManager(auth_manager.get_session())
10-
console = Console()
119

1210
def show(
1311
problem: str = typer.Argument(..., help="Problem slug or number (e.g., 'two-sum' or '1')"),
12+
save: bool = typer.Option(False, "--save", "-s", help="Save problem description to a file"),
1413
compact: bool = typer.Option(False, "--compact", "-c", help="Display in compact layout"),
15-
save: bool = typer.Option(False, "--save", "-s", help="Save problem description to a file")
1614
):
1715
"""
1816
Show problem details including description and test cases

src/lib/problem_ui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ class FunctionMetadata:
3838

3939
class ProblemDetails:
4040
def __init__(self, problem_data: dict):
41-
required_fields = ['questionId', 'title', 'content', 'difficulty']
41+
required_fields = ['questionFrontendId', 'title', 'content', 'difficulty']
4242
if not all(field in problem_data for field in required_fields):
4343
raise ValueError("Missing required problem data fields")
4444

4545
self.data = problem_data
46-
self.question_id: int = problem_data['questionId']
46+
self.question_id: int = problem_data['questionFrontendId']
4747
self.title: str = problem_data['title']
4848
self.difficulty: str = problem_data['difficulty']
4949
self.content: str = problem_data['content']

src/server/session_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import json
2-
import os
32
from pathlib import Path
43
from typing import Optional, Dict
4+
import typer
55

66
class SessionManager:
77
def __init__(self):
8-
# Create config directory in user's home directory
9-
self.config_dir = Path.home() / '.leetcode-cli'
8+
self.config_dir = Path(typer.get_app_dir("leetcode-cli"))
109
self.config_file = self.config_dir / 'session.json'
1110
self._ensure_config_dir()
1211

src/server/solution_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def get_question_data(self, question_identifier: str) -> Dict[str, Any]:
4949
query questionData($titleSlug: String!) {
5050
question(titleSlug: $titleSlug) {
5151
questionId
52+
questionFrontendId
5253
title
5354
titleSlug
5455
content
@@ -98,7 +99,7 @@ def submit_solution(self, title_slug: str, code: str, lang: str = "python3") ->
9899
if not question_data:
99100
return {"success": False, "error": "Question data not found"}
100101

101-
question_id = question_data['questionId']
102+
question_id = question_data['questionFrontendId']
102103
submit_url = f"{self.BASE_URL}/problems/{title_slug}/submit/"
103104

104105
csrf_token = self._get_csrf_token()
@@ -157,7 +158,7 @@ def test_solution(self, title_slug: str, code: str, lang: str = "python3", full:
157158
if not question_data:
158159
return {"success": False, "error": "Question data not found"}
159160

160-
question_id = question_data['questionId']
161+
question_id = question_data['questionFrontendId']
161162
test_cases = question_data['exampleTestcaseList']
162163

163164
endpoint = 'submit' if full else 'interpret_solution'

0 commit comments

Comments
 (0)