1
- import json
2
1
import time
3
2
from datetime import timezone , timedelta , datetime
4
3
@@ -60,18 +59,18 @@ def get_question_detail(self, question_title_slug: str, retry: int = 3) -> dict:
60
59
form1 = {
61
60
'operationName' : 'globalData' ,
62
61
'query' : 'query globalData {\n feature {\n questionTranslation\n subscription\n signUp\n '
63
- 'discuss\n mockInterview\n contest\n store\n book\n chinaProblemDiscuss\n '
64
- 'socialProviders\n studentFooter\n cnJobs\n enableLsp\n enableWs\n '
65
- 'enableDebugger\n enableDebuggerAdmin\n enableDarkMode\n tasks\n '
66
- 'leetbook\n __typename\n }\n userStatus {\n isSignedIn\n isAdmin\n '
67
- 'isStaff\n isSuperuser\n isTranslator\n isPremium\n isVerified\n '
68
- 'isPhoneVerified\n isWechatVerified\n checkedInToday\n username\n '
69
- 'realName\n userSlug\n groups\n avatar\n optedIn\n '
70
- 'requestRegion\n region\n activeSessionId\n permissions\n notificationStatus {\n '
71
- 'lastModified\n numUnread\n __typename\n }\n completedFeatureGuides\n '
72
- 'useTranslation\n accountStatus {\n isFrozen\n inactiveAfter\n __typename\n '
73
- '}\n __typename\n }\n siteRegion\n chinaHost\n websocketUrl\n userBannedInfo {\n '
74
- 'bannedData {\n endAt\n bannedType\n __typename\n }\n __typename\n }\n }\n ' ,
62
+ 'discuss\n mockInterview\n contest\n store\n book\n chinaProblemDiscuss\n '
63
+ 'socialProviders\n studentFooter\n cnJobs\n enableLsp\n enableWs\n '
64
+ 'enableDebugger\n enableDebuggerAdmin\n enableDarkMode\n tasks\n '
65
+ 'leetbook\n __typename\n }\n userStatus {\n isSignedIn\n isAdmin\n '
66
+ 'isStaff\n isSuperuser\n isTranslator\n isPremium\n isVerified\n '
67
+ 'isPhoneVerified\n isWechatVerified\n checkedInToday\n username\n '
68
+ 'realName\n userSlug\n groups\n avatar\n optedIn\n '
69
+ 'requestRegion\n region\n activeSessionId\n permissions\n notificationStatus {\n '
70
+ 'lastModified\n numUnread\n __typename\n }\n completedFeatureGuides\n '
71
+ 'useTranslation\n accountStatus {\n isFrozen\n inactiveAfter\n __typename\n '
72
+ '}\n __typename\n }\n siteRegion\n chinaHost\n websocketUrl\n userBannedInfo {\n '
73
+ 'bannedData {\n endAt\n bannedType\n __typename\n }\n __typename\n }\n }\n ' ,
75
74
'variables' : {},
76
75
}
77
76
headers = {
@@ -86,20 +85,20 @@ def get_question_detail(self, question_title_slug: str, retry: int = 3) -> dict:
86
85
'operationName' : 'questionData' ,
87
86
'variables' : {'titleSlug' : question_title_slug },
88
87
'query' : 'query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n '
89
- 'questionId\n questionFrontendId\n categoryTitle\n boundTopicId\n title\n '
90
- 'titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n '
91
- 'difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n '
92
- 'contributors {\n username\n profileUrl\n avatarUrl\n __typename\n '
93
- '}\n langToValidPlayground\n topicTags {\n name\n slug\n '
94
- 'translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n '
95
- 'lang\n langSlug\n code\n __typename\n }\n stats\n hints\n '
96
- 'solution {\n id\n canSeeDetail\n __typename\n }\n status\n '
97
- 'sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n '
98
- 'enableRunCode\n envInfo\n book {\n id\n bookName\n pressName\n '
99
- 'source\n shortDescription\n fullDescription\n bookImgUrl\n '
100
- 'pressImgUrl\n productUrl\n __typename\n }\n isSubscribed\n '
101
- 'isDailyQuestion\n dailyRecordStatus\n editorType\n ugcQuestionId\n style\n '
102
- 'exampleTestcases\n __typename\n }\n }\n ' ,
88
+ 'questionId\n questionFrontendId\n categoryTitle\n boundTopicId\n title\n '
89
+ 'titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n '
90
+ 'difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n '
91
+ 'contributors {\n username\n profileUrl\n avatarUrl\n __typename\n '
92
+ '}\n langToValidPlayground\n topicTags {\n name\n slug\n '
93
+ 'translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n '
94
+ 'lang\n langSlug\n code\n __typename\n }\n stats\n hints\n '
95
+ 'solution {\n id\n canSeeDetail\n __typename\n }\n status\n '
96
+ 'sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n '
97
+ 'enableRunCode\n envInfo\n book {\n id\n bookName\n pressName\n '
98
+ 'source\n shortDescription\n fullDescription\n bookImgUrl\n '
99
+ 'pressImgUrl\n productUrl\n __typename\n }\n isSubscribed\n '
100
+ 'isDailyQuestion\n dailyRecordStatus\n editorType\n ugcQuestionId\n style\n '
101
+ 'exampleTestcases\n __typename\n }\n }\n ' ,
103
102
}
104
103
105
104
try :
@@ -157,17 +156,17 @@ def format_question_detail(question_detail: dict) -> dict:
157
156
'relative_path_cn' : path_cn ,
158
157
'relative_path_en' : path_en ,
159
158
'title_cn' : question_detail .get ('translatedTitle' )
160
- or question_title_en
161
- or '' ,
159
+ or question_title_en
160
+ or '' ,
162
161
'title_en' : question_title_en or '' ,
163
162
'question_title_slug' : question_title_slug ,
164
163
'content_en' : question_detail .get ('content' ),
165
164
'content_cn' : question_detail .get ('translatedContent' )
166
- or question_detail .get ('content' )
167
- or '' ,
165
+ or question_detail .get ('content' )
166
+ or '' ,
168
167
'tags_en' : [e ['name' ] for e in topic_tags if e ['name' ]] or [],
169
168
'tags_cn' : [e ['translatedName' ] for e in topic_tags if e ['translatedName' ]]
170
- or [],
169
+ or [],
171
170
'difficulty_en' : question_detail .get ('difficulty' ),
172
171
'difficulty_cn' : difficulty .get (question_detail .get ('difficulty' )),
173
172
'code_snippets' : question_detail .get ('codeSnippets' ) or [],
@@ -316,7 +315,6 @@ def get_contests(fetch_new=True) -> List:
316
315
time .sleep (0.3 )
317
316
question_details [slug ] = Spider .format_question_detail (detail )
318
317
319
-
320
318
# 周赛场次列表
321
319
contest_list = get_contests (refresh_all )
322
320
cls = []
0 commit comments