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

Method get_data

solution/main.py:300–330  ·  view source on GitHub ↗
(self, retry: int = 3)

Source from the content-addressed store, hash-verified

298 return datetime.fromtimestamp(timestamp, tz).strftime("%Y-%m-%d %H:%M")
299
300 def get_data(self, retry: int = 3):
301 try:
302 print(self.contest_url)
303 headers = {
304 'User-Agent': user_agent,
305 'Host': 'leetcode.cn',
306 'content-type': 'application/json',
307 'Accept': 'application/json, text/javascript, */*; q=0.01',
308 }
309 res = requests.get(
310 self.contest_url, timeout=6, verify=False, headers=headers
311 )
312 res = res.json()
313 if not res or "error" in res or not res["questions"]:
314 return {}
315 questions = res["questions"]
316 question_slugs = [q["title_slug"] for q in questions]
317 return {
318 "contest_title": self.contest_title,
319 "contest_title_en": self.contest_title_en,
320 "contest_title_slug": res["contest"]["title_slug"],
321 "contest_id": res["contest"]["id"],
322 "contest_start_time": res["contest"]["origin_start_time"],
323 "contest_duration": res["contest"]["duration"],
324 "user_num": res["user_num"],
325 "question_slugs": question_slugs,
326 }
327 except Exception as e:
328 print(e)
329 time.sleep(2)
330 return self.get_data(retry - 1) if retry > 0 else {}
331
332 @staticmethod
333 def format(data: dict) -> List:

Callers 1

get_contestsFunction · 0.95

Calls 2

printFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected