mirror of https://github.com/doocs/leetcode.git
feat: add past contests
This commit is contained in:
parent
ba518558c7
commit
b13b115425
|
|
@ -4,6 +4,7 @@
|
|||
/node_modules
|
||||
/solution/result.json
|
||||
/solution/contest.json
|
||||
/solution/contest_list.json
|
||||
/solution/raw.json
|
||||
/lcof/lcof.json
|
||||
/lcof/lcof_list.json
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
## 算法全解
|
||||
|
||||
- [LeetCode](/solution/README.md)
|
||||
- [往期竞赛合集](/solution/CONTEST_README.md)
|
||||
- [剑指 Offer(第 2 版)](/lcof/README.md)
|
||||
- [剑指 Offer(专项突击版)](/lcof2/README.md)
|
||||
- [程序员面试金典(第 6 版)](/lcci/README.md)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ Complete solutions to [LeetCode](https://leetcode.com/problemset/all/), [LCOF](h
|
|||
## Solutions
|
||||
|
||||
- [LeetCode](/solution/README_EN.md)
|
||||
- [Past Contests](/solution/CONTEST_README_EN.md)
|
||||
- [LCOF: Coding Interviews, 2nd Edition](/lcof/README_EN.md)
|
||||
- [LCCI: Cracking the Coding Interview, 6th Edition](/lcci/README_EN.md)
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import time
|
||||
from itertools import chain
|
||||
|
||||
import requests
|
||||
|
||||
|
|
@ -11,6 +12,15 @@ biweekly_url = 'https://leetcode.cn/contest/api/info/biweekly-contest-{}/'
|
|||
questions = {}
|
||||
|
||||
|
||||
def format_time(timestamp):
|
||||
return time.strftime('%Y-%m-%d %H:%M', time.localtime(timestamp))
|
||||
|
||||
|
||||
def format_duration(seconds):
|
||||
m = seconds // 60
|
||||
return f'{m} 分钟'
|
||||
|
||||
|
||||
def weekly(contest):
|
||||
url = weekly_url.format(contest)
|
||||
time.sleep(1)
|
||||
|
|
@ -47,13 +57,17 @@ def handle(result: dict):
|
|||
questions[q['title_slug']] = {
|
||||
'contest_title': result['title'],
|
||||
'contest_title_en': result['title_en'],
|
||||
'contest_title_slug': result['contest']['title_slug']
|
||||
'contest_title_slug': result['contest']['title_slug'],
|
||||
'contest_id': result['contest']['id'],
|
||||
'contest_start_time': result['contest']['origin_start_time'],
|
||||
'contest_duration': result['contest']['duration']
|
||||
}
|
||||
|
||||
|
||||
def run():
|
||||
weekly_res = []
|
||||
biweekly_res = []
|
||||
contest_list = []
|
||||
for i in weekly_range:
|
||||
res = weekly(i)
|
||||
if res and 'error' in res:
|
||||
|
|
@ -64,10 +78,59 @@ def run():
|
|||
if res and 'error' in res:
|
||||
break
|
||||
biweekly_res.append(res)
|
||||
for v in weekly_res + biweekly_res:
|
||||
for v in chain(weekly_res, biweekly_res):
|
||||
handle(v)
|
||||
contest_list.append([
|
||||
v['contest']['id'], v['title'], v['title_en'], v['questions'], v['contest']['start_time'],
|
||||
v['contest']['duration']
|
||||
])
|
||||
|
||||
contest_list.sort(reverse=True)
|
||||
with open("contest.json", 'w', encoding='utf-8') as f:
|
||||
f.write(json.dumps(questions))
|
||||
with open('contest_list.json', 'w', encoding='utf-8') as f:
|
||||
f.write(json.dumps(contest_list))
|
||||
|
||||
|
||||
run()
|
||||
# ["id", "title", "title_en", "questions", "start_time", "duration"]
|
||||
|
||||
def generate_contest_list():
|
||||
with open('./result.json', 'r', encoding='utf-8') as f:
|
||||
result = json.loads(f.read())
|
||||
m = {item['question_title_slug']: item for item in result}
|
||||
with open('contest_list.json', 'r', encoding='utf-8') as f:
|
||||
contest_list = list(json.loads(f.read()))
|
||||
|
||||
contest_readme_prefix = """# 力扣竞赛\n\n[English Version](/solution/CONTEST_README_EN.md)\n\n
|
||||
## 赛后估分网站\n\nhttps://lcpredictor.herokuapp.com/\n\n## 往期竞赛\n\n"""
|
||||
contest_readme_en_prefix = """# LeetCode Contest\n\n[中文文档](/solution/CONTEST_README.md)\n\n
|
||||
## Rating Predictor\n
|
||||
Get your rating changes right after the completion of LeetCode contests, https://lcpredictor.herokuapp.com/\n
|
||||
## Past Contests\n\n"""
|
||||
|
||||
items = []
|
||||
en_items = []
|
||||
|
||||
for cid, title, title_en, qs, start_time, duration in contest_list:
|
||||
v = "#### " + title + f'({format_time(start_time) + ", " + format_duration(duration)})' + "\n\n"
|
||||
v_en = "#### " + title_en + "\n\n"
|
||||
for q in qs:
|
||||
slug = q['title_slug']
|
||||
data = m.get(slug)
|
||||
if data is None:
|
||||
continue
|
||||
v += f'- [{str(int(data["frontend_question_id"])) + ". " + data["title_cn"]}]({data["relative_path_cn"]})\n'
|
||||
v_en += f'- [{str(int(data["frontend_question_id"])) + ". " + data["title_en"]}]({data["relative_path_en"]})\n'
|
||||
if qs:
|
||||
items.append(v)
|
||||
en_items.append(v_en)
|
||||
content_cn = contest_readme_prefix + "\n\n".join(items)
|
||||
content_en = contest_readme_en_prefix + "\n\n".join(en_items)
|
||||
with open("CONTEST_README.md", 'w', encoding='utf-8') as f:
|
||||
f.write(content_cn)
|
||||
with open("CONTEST_README_EN.md", 'w', encoding='utf-8') as f:
|
||||
f.write(content_en)
|
||||
|
||||
|
||||
# run()
|
||||
generate_contest_list()
|
||||
|
|
|
|||
Loading…
Reference in New Issue