@@ -38,13 +38,12 @@ def get_question_metadata(api, title_slug):
38
38
39
39
try :
40
40
response = api .graphql_post (body = graphql_request )
41
+ return response
41
42
except ApiException as e :
42
43
print (
43
44
f'Exception occurred when contacting the Leetcode GraphQL API: ${ e } ' )
44
45
exit ()
45
46
46
- return response
47
-
48
47
49
48
def construct_company_tag_list (company_tags_json , sections ):
50
49
companies = []
@@ -60,13 +59,26 @@ def construct_company_tag_list(company_tags_json, sections):
60
59
return sorted (companies , key = lambda d : d ['frequency' ], reverse = True )
61
60
62
61
63
- def update_question_metadata (question , title , difficulty , companies , is_premium ):
64
- print (f"🔄 Updating question metadata for { title } " )
62
+ def update_question_metadata (question , response ):
63
+ print (f'''🔄 Updating question metadata for { question ["title" ]} ''' )
64
+
65
+ question_title = response .data .question .title
66
+ question_difficulty = response .data .question .difficulty
67
+ question_company_tags = json .loads (
68
+ response .data .question .company_tag_stats )
69
+ question_is_premium = response .data .question .is_paid_only
70
+
71
+ # Retrieve companies who have asked this question for the following two
72
+ # company_tag_stat sections:
73
+ # 1. 0-6 months
74
+ # 2. 6 months to 1 year
75
+ companies = construct_company_tag_list (
76
+ question_company_tags , ["1" , "2" ])
65
77
66
- question ["title" ] = title
67
- question ["difficulty" ] = difficulty
78
+ question ["title" ] = question_title
79
+ question ["difficulty" ] = question_difficulty
68
80
question ["companies" ] = companies
69
- question ["premium" ] = is_premium
81
+ question ["premium" ] = question_is_premium
70
82
71
83
72
84
def read_questions (file_name ):
@@ -106,21 +118,7 @@ def main(file_name):
106
118
107
119
response = get_question_metadata (api , title_slug )
108
120
109
- question_title = response .data .question .title
110
- question_difficulty = response .data .question .difficulty
111
- question_company_tags = json .loads (
112
- response .data .question .company_tag_stats )
113
- question_is_premium = response .data .question .is_paid_only
114
-
115
- # Retrieve companies who have asked this question within the following two
116
- # company_tag_stat sections:
117
- # 1. 0-6 months
118
- # 2. 6 months to 1 year
119
- companies = construct_company_tag_list (
120
- question_company_tags , ["1" , "2" ])
121
-
122
- update_question_metadata (question , question_title , question_difficulty ,
123
- companies , question_is_premium )
121
+ update_question_metadata (question , response )
124
122
125
123
write_questions (file_name , questions )
126
124
0 commit comments