4
4
from color import Colors
5
5
from config_setup import (
6
6
save_credentials_to_config ,
7
- load_credentials_from_config , load_user_data_from_config , save_user_data_to_config ,
7
+ load_credentials_from_config ,
8
+ load_user_data_from_config ,
9
+ save_user_data_to_config ,
8
10
)
9
11
import leetcode
10
12
import leetcode .auth
@@ -165,7 +167,7 @@ def print_submission_result(submission): # used python-leetcode library
165
167
166
168
167
169
def initialize_leetcode_api_instance (
168
- leetcode_session , leetcode_csrf_token
170
+ leetcode_session , leetcode_csrf_token
169
171
): # used python-leetcode library
170
172
configuration = leetcode .Configuration ()
171
173
csrf_token = leetcode_csrf_token
@@ -199,7 +201,7 @@ def interpret_solution(title_slug, payload, api_instance):
199
201
200
202
# --submit
201
203
def submit_solution (
202
- api_instance , title_slug , code , question_id , lang_name
204
+ api_instance , title_slug , code , question_id , lang_name
203
205
): # used python-leetcode library
204
206
submission = leetcode .Submission (
205
207
judge_type = "large" ,
@@ -335,9 +337,9 @@ def get_question_data_by_id(api_instance, q):
335
337
api_response = execute_graphql_query (api_instance , data )
336
338
337
339
if (
338
- api_response
339
- and "data" in api_response
340
- and "problemsetQuestionList" in api_response ["data" ]
340
+ api_response
341
+ and "data" in api_response
342
+ and "problemsetQuestionList" in api_response ["data" ]
341
343
):
342
344
return api_response ["data" ]["problemsetQuestionList" ]["questions" ]
343
345
return None
@@ -472,20 +474,28 @@ def display_question_detail(api_instance, title_slug):
472
474
if user_lang :
473
475
write_code_snippet_to_file (question_detail_data , user_lang , title_slug )
474
476
else :
475
- available_languages = get_available_languages_and_code_snippets (question_detail_data )
477
+ available_languages = get_available_languages_and_code_snippets (
478
+ question_detail_data
479
+ )
476
480
if not available_languages :
477
481
print ("No code snippets available." )
478
482
return
479
483
print ("Available Languages:" )
480
484
for index , (lang_slug , lang_name ) in enumerate (available_languages , 1 ):
481
485
print (f"{ index } . { lang_slug } " )
482
- lang_input = input ("Enter the displayed index of the language you want to code: " ).strip ().lower ()
486
+ lang_input = (
487
+ input ("Enter the displayed index of the language you want to code: " )
488
+ .strip ()
489
+ .lower ()
490
+ )
483
491
try :
484
492
lang_index = int (lang_input )
485
493
if 1 <= lang_index <= len (available_languages ):
486
494
selected_lang = available_languages [lang_index - 1 ][0 ]
487
495
print (selected_lang )
488
- write_code_snippet_to_file (question_detail_data , selected_lang , title_slug )
496
+ write_code_snippet_to_file (
497
+ question_detail_data , selected_lang , title_slug
498
+ )
489
499
else :
490
500
print ("Invalid index. Please enter a valid index." )
491
501
except ValueError :
@@ -494,7 +504,10 @@ def display_question_detail(api_instance, title_slug):
494
504
495
505
def write_code_snippet_to_file (question_detail_data , lang , title_slug ):
496
506
code_snippets = question_detail_data .get ("codeSnippets" , [])
497
- code = next ((snippet ["code" ] for snippet in code_snippets if snippet ["langSlug" ] == lang ), None )
507
+ code = next (
508
+ (snippet ["code" ] for snippet in code_snippets if snippet ["langSlug" ] == lang ),
509
+ None ,
510
+ )
498
511
if code :
499
512
lang_extension = LANG_EXTENSIONS .get (lang )
500
513
if lang_extension :
@@ -621,9 +634,7 @@ def replace_files():
621
634
default = "" ,
622
635
help = "Set user preferred language (e.g., python3)" ,
623
636
)
624
- @click .option (
625
- "--lib" , is_flag = True , default = False , help = "Show usage information"
626
- )
637
+ @click .option ("--lib" , is_flag = True , default = False , help = "Show usage information" )
627
638
@click .option (
628
639
"--question" ,
629
640
"-q" ,
0 commit comments