|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
""" |
|
3
|
|
|
:author @wangwangit |
|
4
|
|
|
cron: 10 10 * * * |
|
5
|
|
|
new Env('LeetCode 每日一题'); |
|
6
|
|
|
""" |
|
7
|
|
|
|
|
8
|
|
|
import requests |
|
9
|
|
|
|
|
10
|
|
|
from notify_mtr import send |
|
11
|
|
|
from utils import get_data |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class LeetCode: |
|
15
|
|
|
@staticmethod |
|
16
|
|
|
def main(): |
|
17
|
|
|
base_url = "https://leetcode-cn.com" |
|
18
|
|
|
|
|
19
|
|
|
# 获取今日每日一题的题名(英文) |
|
20
|
|
|
res = requests.post( |
|
21
|
|
|
f"{base_url}/graphql", |
|
22
|
|
|
json={ |
|
23
|
|
|
"operationName": "questionOfToday", |
|
24
|
|
|
"variables": {}, |
|
25
|
|
|
"query": "query questionOfToday { todayRecord { " |
|
26
|
|
|
"question { questionFrontendId questionTitleSlug __typename } " |
|
27
|
|
|
"lastSubmission { id __typename } " |
|
28
|
|
|
"date userStatus __typename } }", |
|
29
|
|
|
}, |
|
30
|
|
|
).json() |
|
31
|
|
|
title_slug = ( |
|
32
|
|
|
res.get("data") |
|
33
|
|
|
.get("todayRecord")[0] |
|
34
|
|
|
.get("question") |
|
35
|
|
|
.get("questionTitleSlug") |
|
36
|
|
|
) |
|
37
|
|
|
|
|
38
|
|
|
# 获取今日每日一题的所有信息 |
|
39
|
|
|
url = f"{base_url}/problems/{title_slug}" |
|
40
|
|
|
res = requests.post( |
|
41
|
|
|
f"{base_url}/graphql", |
|
42
|
|
|
json={ |
|
43
|
|
|
"operationName": "questionData", |
|
44
|
|
|
"variables": {"titleSlug": title_slug}, |
|
45
|
|
|
"query": "query questionData($titleSlug: String!) " |
|
46
|
|
|
"{ question(titleSlug: $titleSlug) { questionId questionFrontendId " |
|
47
|
|
|
"boundTopicId title titleSlug content translatedTitle translatedContent" |
|
48
|
|
|
" isPaidOnly difficulty likes dislikes isLiked similarQuestions " |
|
49
|
|
|
"contributors { username profileUrl avatarUrl __typename } " |
|
50
|
|
|
"langToValidPlayground topicTags " |
|
51
|
|
|
"{ name slug translatedName __typename } " |
|
52
|
|
|
"companyTagStats codeSnippets { lang langSlug code __typename } " |
|
53
|
|
|
"stats hints solution { id canSeeDetail __typename } " |
|
54
|
|
|
"status sampleTestCase metaData judgerAvailable judgeType " |
|
55
|
|
|
"mysqlSchemas enableRunCode envInfo book " |
|
56
|
|
|
"{ id bookName pressName source shortDescription fullDescription" |
|
57
|
|
|
" bookImgUrl pressImgUrl productUrl __typename } " |
|
58
|
|
|
"isSubscribed isDailyQuestion dailyRecordStatus " |
|
59
|
|
|
"editorType ugcQuestionId style __typename } }", |
|
60
|
|
|
}, |
|
61
|
|
|
).json() |
|
62
|
|
|
|
|
63
|
|
|
# 题目 |
|
64
|
|
|
question = res.get("data").get("question") |
|
65
|
|
|
# 题号 |
|
66
|
|
|
num = question.get("questionFrontendId") |
|
67
|
|
|
# 题名(中文) |
|
68
|
|
|
zh_title = question.get("translatedTitle") |
|
69
|
|
|
return f'<a href="{url}">{num}. {zh_title}</a>' |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
if __name__ == "__main__": |
|
73
|
|
|
_data = get_data() |
|
74
|
|
|
leetcode = _data.get("LEETCODE") |
|
75
|
|
|
if leetcode: |
|
76
|
|
|
result = LeetCode().main() |
|
77
|
|
|
send("LeetCode 每日一题", result) |
|
78
|
|
|
|