|
| 1 | +import json |
1 | 2 | import os
|
2 | 3 | import re
|
| 4 | +import requests |
3 | 5 | from collections import defaultdict
|
4 | 6 |
|
5 | 7 |
|
| 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 | + |
6 | 31 | for contest_file in ["docs/contest.md", "docs-en/contest.md"]:
|
7 | 32 | with open(contest_file, "r", encoding="utf-8") as f:
|
8 | 33 | content = f.read()
|
@@ -82,7 +107,7 @@ def get_paths(dirs: str, m: int):
|
82 | 107 | for p in sorted(get_paths(dir, m)):
|
83 | 108 | # example:
|
84 | 109 | # 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}" |
86 | 111 | with open(p, "r", encoding="utf-8") as f:
|
87 | 112 | content = f.read()
|
88 | 113 |
|
@@ -165,7 +190,10 @@ def get_paths(dirs: str, m: int):
|
165 | 190 | comments: true
|
166 | 191 | ---
|
167 | 192 | """
|
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 | + ) |
169 | 197 | with open(new_path, "w", encoding="utf-8") as f:
|
170 | 198 | f.write(content)
|
171 | 199 |
|
|
0 commit comments