Skip to content

Commit 5ebc2d5

Browse files
committed
保存工具代码
1 parent 7b434bd commit 5ebc2d5

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

tools/1-add-title-and-url.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import random
1212
import time
1313
from re import search
14+
from datetime import datetime
1415

1516

1617
def get_problems(json_data):
@@ -26,7 +27,7 @@ def get_data(url):
2627
r = requests.get(url)
2728
if r.status_code == 200:
2829
result = r.text
29-
f = open('./leetcode.json', 'w')
30+
f = open('./leetcode-%s.json'%(datetime.today().strftime('%Y%m%d')), 'w')
3031
f.write(result)
3132
f.close
3233
return result
@@ -40,15 +41,12 @@ def get_data(url):
4041
for problem in problems:
4142
id = problem["stat"]["frontend_question_id"]
4243

43-
if id < 3251:
44-
continue
45-
4644
title = "= %d. %s" %(id, problem["stat"]["question__title"])
4745
url = "https://leetcode.com/problems/%s/[LeetCode - %d. %s ^]" % (problem["stat"]["question__title_slug"], id, problem["stat"]["question__title"])
48-
filename = "%04d-%s.adoc"%(problem["stat"]["frontend_question_id"], problem["stat"]["question__title_slug"])
46+
filename = "%04d-%s.adoc"%(id, problem["stat"]["question__title_slug"])
4947

5048
f = open("../docs/"+filename, "a")
51-
f.write("[#%04d-%s]\n"%(problem["stat"]["frontend_question_id"], problem["stat"]["question__title_slug"]))
49+
f.write("[#%04d-%s]\n"%(id, problem["stat"]["question__title_slug"]))
5250
f.write(title)
5351
f.write("\n\n")
5452
f.write(url)

tools/2-fetch-problems.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,23 @@ def fetch_problem(title_slug):
4848
else:
4949
return None
5050

51+
# 如果是锁定题目,则 data.question.content 为 null;
52+
def fetch_translations(title_slug):
53+
url = 'https://leetcode.cn/graphql/'
54+
headers = {'content-type': 'application/json'}
55+
data = '{"query":"\n query questionTranslations($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n translatedTitle\n translatedContent\n }\n}\n ","variables":{"titleSlug":"%s"},"operationName":"questionTranslations"}' % title_slug
56+
response = requests.post(url, headers=headers, data=data)
57+
if response.status_code == 200:
58+
return response.text
59+
else:
60+
return None
61+
5162
problem_list = get_problems()
5263

5364
for problem in problem_list:
5465
id = problem["stat"]["frontend_question_id"]
5566
titleSlug = problem["stat"]["question__title_slug"]
56-
filename = "%04d-%s.adoc"%(problem["stat"]["frontend_question_id"], titleSlug)
67+
filename = "%04d-%s.adoc"%(id, titleSlug)
5768

5869
filepath = "../docs/"+filename
5970
problem_file = filepath+".json"

tools/7-download-images.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
a = [];
2-
document.querySelectorAll('div.w-full > div.break-words > div > div > div > div > img').forEach(e => a.push(e.src));
2+
document.querySelectorAll('div.h-full.w-full > div div > div.w-full > div.break-words > div > div img').forEach(e => a.push(e.src));
33
console.log("count=0\nfor f in '" + a.join("' '") + "'\ndo\n ((count = count + 1))\n cnt=$(printf \"%02d\" count)\n wget $f -O \"-$cnt.png\"\ndone");
44

55
// 从 LeetCode 下载图片

0 commit comments

Comments
 (0)