File tree Expand file tree Collapse file tree 6 files changed +46
-1
lines changed Expand file tree Collapse file tree 6 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1- typer
1+ typer
2+ requests
Original file line number Diff line number Diff line change 11import typer
2+ from server .api import fetch_problem_list
23
34def 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 ()
Original file line number Diff line number Diff line change 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" ]
Original file line number Diff line number Diff line change 1+ BASE_URL = "https://leetcode.com/graphql"
You can’t perform that action at this time.
0 commit comments