@@ -38,13 +38,12 @@ def get_question_metadata(api, title_slug):
3838
3939 try :
4040 response = api .graphql_post (body = graphql_request )
41+ return response
4142 except ApiException as e :
4243 print (
4344 f'Exception occurred when contacting the Leetcode GraphQL API: ${ e } ' )
4445 exit ()
4546
46- return response
47-
4847
4948def construct_company_tag_list (company_tags_json , sections ):
5049 companies = []
@@ -60,13 +59,26 @@ def construct_company_tag_list(company_tags_json, sections):
6059 return sorted (companies , key = lambda d : d ['frequency' ], reverse = True )
6160
6261
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" ])
6577
66- question ["title" ] = title
67- question ["difficulty" ] = difficulty
78+ question ["title" ] = question_title
79+ question ["difficulty" ] = question_difficulty
6880 question ["companies" ] = companies
69- question ["premium" ] = is_premium
81+ question ["premium" ] = question_is_premium
7082
7183
7284def read_questions (file_name ):
@@ -106,21 +118,7 @@ def main(file_name):
106118
107119 response = get_question_metadata (api , title_slug )
108120
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 )
124122
125123 write_questions (file_name , questions )
126124
0 commit comments