Skip to content

Commit 94e6f11

Browse files
authored
Small updates to update_questions.py (#233)
1 parent a2e97ea commit 94e6f11

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

cron/update_questions.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -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

4948
def 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

7284
def 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

Comments
 (0)