Conditions | 1 |
Total Lines | 55 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # -*- coding: utf-8 -*- |
||
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 | |||
78 |