MCPcopy
hub / github.com/doocs/leetcode / get_all_questions_v2

Method get_all_questions_v2

solution/main.py:58–85  ·  view source on GitHub ↗
(self, retry: int = 3, limit: int = 10000)

Source from the content-addressed store, hash-verified

56 return self.get_all_questions(retry - 1) if retry > 0 else []
57
58 def get_all_questions_v2(self, retry: int = 3, limit: int = 10000) -> List:
59 headers = {
60 "Cookie": self.cookie_en,
61 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0",
62 "Content-Type": "application/json",
63 }
64 form = {
65 "query": "\n query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {\n problemsetQuestionList: questionList(\n categorySlug: $categorySlug\n limit: $limit\n skip: $skip\n filters: $filters\n ) {\n total: totalNum\n questions: data {\n acRate\n difficulty\n freqBar\n frontendQuestionId: questionFrontendId\n isFavor\n paidOnly: isPaidOnly\n status\n title\n titleSlug\n topicTags {\n name\n id\n slug\n }\n hasSolution\n hasVideoSolution\n }\n }\n}\n ",
66 "variables": {
67 "categorySlug": "all-code-essentials",
68 "skip": 0,
69 "limit": limit,
70 "filters": {"orderBy": "FRONTEND_ID", "sortOrder": "DESCENDING"},
71 },
72 "operationName": "problemsetQuestionList",
73 }
74 try:
75 resp = requests.post(
76 "https://leetcode.com/graphql",
77 headers=headers,
78 data=json.dumps(form),
79 timeout=20,
80 )
81 return resp.json()["data"]["problemsetQuestionList"]["questions"]
82 except Exception as e:
83 print("get_all_questions_v2", e)
84 time.sleep(2)
85 return self.get_all_questions_v2(retry - 1, limit) if retry > 0 else []
86
87 def get_question_detail_en(self, question_title_slug: str, retry: int = 3) -> dict:
88 headers = {

Callers 1

runFunction · 0.95

Calls 1

printFunction · 0.85

Tested by

no test coverage detected