Skip to content

Commit 190eb02

Browse files
committed
Crawl memory usage for AC solution
1 parent bca4b0c commit 190eb02

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

LeetCode_AC_Code_Crawler.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,28 @@ def save_ac_code(ac_list, premium):
6363
# Get submission details
6464
testcase = soup.find("span", id = "result_progress").text
6565
runtime = soup.find("span", id = "result_runtime").text
66-
ranking = soup.find("div", style="line-height: 1em; position: relative;")
67-
if ranking:
68-
ranking = ranking.text.replace("\n", " ").replace(" ", "")[15:]
69-
else:
70-
ranking = "Your runtime beats 00.00 % of submissions."
66+
memory = soup.find("span", id = "result_memory").text
67+
ranking_list = soup.find_all("div", style="line-height: 1em; position: relative;")
68+
if len(ranking_list) == 2:
69+
ranking_runtime = ranking_list[0].text.replace("\n", " ").replace(" ", "")[15:]
70+
ranking_memory = ranking_list[1].text.replace("\n", " ").replace(" ", "")[15:]
71+
elif len(ranking_list) == 1:
72+
ranking_runtime = ranking_list[0].text.replace("\n", " ").replace(" ", "")[15:]
73+
ranking_memory = "Your memory usage beats 00.00 % of submissions."
74+
elif len(ranking_list) == 0:
75+
ranking_runtime = "Your runtime beats 00.00 % of submissions."
76+
ranking_memory = "Your memory usage beats 00.00 % of submissions."
77+
7178
submission_detail = ("/*\n" + "Submission Detail:{" +
72-
"\n Difficulty : " + difficulty +
73-
"\n Acceptance Rate : " + str(ac["ac_rate"]*100)[:5] + " %" +
74-
"\n Runtime : " + runtime +
75-
"\n Testcase : " + testcase + " passed" +
76-
"\n Ranking : " + ranking +
77-
"\n}\n*/\n\n")
79+
"\n Difficulty : " + difficulty +
80+
"\n Acceptance Rate : " + str(ac["ac_rate"]*100)[:5] + " %" +
81+
"\n Runtime : " + runtime +
82+
"\n Memory Usage : " + memory +
83+
"\n Testcase : " + testcase + " passed" +
84+
"\n Ranking : " +
85+
"\n " + ranking_runtime +
86+
"\n " + ranking_memory +
87+
"\n}\n*/\n\n")
7888

7989
# Get ac code
8090
script = soup.find("script", text = re.compile("submissionCode:"))

0 commit comments

Comments
 (0)