Skip to content

Commit 535709f

Browse files
feat: add problem fetching
1 parent 6f9a886 commit 535709f

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
typer
1+
typer
2+
requests

src/commands/__init__.py

Whitespace-only changes.

src/commands/list.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import typer
2+
from server.api import fetch_problem_list
23

34
def list():
45
"""List all available LeetCode problems."""
56
typer.echo("Fetching problem list...")
7+
data = fetch_problem_list()
8+
9+
for problem in data:
10+
typer.echo(f"{problem['questionFrontendId']}. {problem['title']}")
11+
typer.echo(f"Difficulty: {problem['difficulty']}")
12+
tags = ", ".join(tag["name"] for tag in problem["topicTags"])
13+
typer.echo(f"Tags: {tags}")
14+
typer.echo()

src/server/__init__.py

Whitespace-only changes.

src/server/api.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import requests
2+
from .config import BASE_URL
3+
4+
def fetch_problem_list():
5+
"""Fetches a list of LeetCode problems from the API."""
6+
query = {
7+
"query": """
8+
query {
9+
problemsetQuestionListV2(
10+
categorySlug: ""
11+
limit: 10
12+
skip: 0
13+
) {
14+
questions {
15+
questionFrontendId
16+
title
17+
difficulty
18+
topicTags {
19+
name
20+
}
21+
}
22+
}
23+
}
24+
"""
25+
}
26+
27+
response = requests.post(BASE_URL, json=query)
28+
data = response.json()
29+
30+
if "errors" in data:
31+
print("Error fetching problems:", data["errors"])
32+
return []
33+
34+
return data["data"]["problemsetQuestionList"]["questions"]

src/server/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BASE_URL = "https://leetcode.com/graphql"

0 commit comments

Comments
 (0)