MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / get_title_with_slug

Method get_title_with_slug

src/leetcode.py:115–156  ·  view source on GitHub ↗
(self, id, slug, paid_only)

Source from the content-addressed store, hash-verified

113 return j['data']['question']['translatedTitle']
114
115 def get_title_with_slug(self, id, slug, paid_only):
116 content = self.get_problem_content(id)
117
118 if content:
119 j = json.loads(content)
120 return j['data']['question']['translatedTitle']
121
122 session = requests.Session()
123 headers = {'User-Agent': user_agent, 'Connection':
124 'keep-alive', 'Content-Type': 'application/json',
125 'Referer': withUrl('problems/') + slug}
126
127 url = withUrl('graphql')
128 params = {'operationName': "getQuestionDetail",
129 'variables': {'titleSlug': slug},
130 'query': '''query getQuestionDetail($titleSlug: String!) {
131 question(titleSlug: $titleSlug) {
132 questionId
133 questionFrontendId
134 questionTitle
135 questionTitleSlug
136 translatedTitle
137 translatedContent
138 content
139 difficulty
140 stats
141 similarQuestions
142 categoryTitle
143 topicTags {
144 name
145 slug
146 }
147 }
148 }'''}
149
150 json_data = json.dumps(params).encode('utf8')
151 resp = session.post(url, data=json_data, headers=headers, timeout=10)
152 content = resp.text
153 j = json.loads(content)
154 j['data']['question']['paid_only'] = paid_only
155 self.save_problem(id, json.dumps(j))
156 return j['data']['question']['translatedTitle']
157
158 def get_update_db_time(self):
159 t = self.dict.get("leetcode_update_db_time")

Callers 1

update_dbMethod · 0.95

Calls 3

get_problem_contentMethod · 0.95
save_problemMethod · 0.95
withUrlFunction · 0.85

Tested by

no test coverage detected