Skip to content

Commit b2f0fdf

Browse files
committed
feat: add rating data
1 parent ba9d7c1 commit b2f0fdf

File tree

3 files changed

+20108
-2
lines changed

3 files changed

+20108
-2
lines changed

main.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1+
import json
12
import os
23
import re
4+
import requests
35
from collections import defaultdict
46

57

8+
def load_ratings():
9+
res = {}
10+
if os.path.exists("rating.json"):
11+
with open("rating.json", "r", encoding="utf-8") as f:
12+
ratings = json.loads(f.read())
13+
for item in ratings:
14+
res[item["ID"]] = item
15+
16+
url = "https://zerotrac.github.io/leetcode_problem_rating/data.json"
17+
try:
18+
resp = requests.get(url)
19+
if resp.status_code == 200:
20+
ratings = resp.json()
21+
for item in ratings:
22+
res[item["ID"]] = item
23+
except Exception as e:
24+
print(f"Failed to fetch ratings: {e}")
25+
return res
26+
27+
28+
rating_dict = load_ratings()
29+
30+
631
for contest_file in ["docs/contest.md", "docs-en/contest.md"]:
732
with open(contest_file, "r", encoding="utf-8") as f:
833
content = f.read()
@@ -82,7 +107,7 @@ def get_paths(dirs: str, m: int):
82107
for p in sorted(get_paths(dir, m)):
83108
# example:
84109
# p = 'solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md'
85-
edit_url = f'https://github.com/doocs/leetcode/edit/main/{p}'
110+
edit_url = f"https://github.com/doocs/leetcode/edit/main/{p}"
86111
with open(p, "r", encoding="utf-8") as f:
87112
content = f.read()
88113

@@ -165,7 +190,10 @@ def get_paths(dirs: str, m: int):
165190
comments: true
166191
---
167192
"""
168-
content = f"---\ncomments: true\nedit_url: {edit_url}\n{tag_headers}---\n\n" + content
193+
content = (
194+
f"---\ncomments: true\nedit_url: {edit_url}\n{tag_headers}---\n\n"
195+
+ content
196+
)
169197
with open(new_path, "w", encoding="utf-8") as f:
170198
f.write(content)
171199

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ hooks:
8787
- hooks/committer.py
8888

8989
markdown_extensions:
90+
- admonition
9091
- pymdownx.superfences
9192
- pymdownx.tabbed:
9293
alternate_style: true

0 commit comments

Comments
 (0)