Skip to content

Commit 4a67de5

Browse files
committed
Formatted the code properly
1 parent 9a68c00 commit 4a67de5

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/arguments/utility.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ def get_ans(self, questions_list):
8484
4) The value of "question_posx" changes according to user input, displaying answer to different questions in "questions_data" list.
8585
3) The answers to the questions requested by the user are stored in cache for faster access time during subsequent calls.
8686
"""
87-
88-
""" Create batch request to get details of all the questions """
87+
# Create batch request to get details of all the questions
8988
batch_ques_id = ""
9089
for question_id in questions_list:
9190
batch_ques_id += str(question_id) + ";"
92-
9391
try:
9492
resp = requests.get(
9593
f"{self.search_content_url}/2.2/questions/{batch_ques_id[:-1]}?order=desc&sort=votes&site=stackoverflow&filter=!--1nZwsgqvRX"
@@ -98,30 +96,36 @@ def get_ans(self, questions_list):
9896
SearchError("Search Failed", "Try connecting to the internet")
9997
sys.exit()
10098
json_ques_data = resp.json()
101-
102-
""" Store the received questions data into the following data format
103-
list( list( question_title, question_link, question_id ) )
99+
"""
100+
Store the received questions data into the following data format:
101+
list( list( question_title, question_link, question_id ) )
104102
"""
105103
questions_data = [[item['title'], item['link'], item['question_id']] for item in json_ques_data["items"] ]
104+
# Clear terminal
105+
os.system('cls' if os.name == 'nt' else 'clear')
106+
107+
# cache array to store the requested answers. Format of storage { question_id:[answer_body, answer_link] }
108+
downloaded_questions_cache = defaultdict(lambda: False)
106109

107-
os.system('cls' if os.name == 'nt' else 'clear') # Clear terminal
110+
# Stores the currently showing question index in questions_data
111+
question_posx = 0
108112

109-
downloaded_questions_cache = defaultdict(lambda: False) # cache array to store the requested answers. Format of storage { question_id:[answer_body, answer_link] }
110-
111-
question_posx = 0 # Stores the currently showing question index in questions_data
112113
while True:
113114
os.system('cls' if os.name == 'nt' else 'clear')
114-
115+
# Printing all the questions. The active question is printed GREEN.
115116
console.rule('[bold blue] Relevant Questions', style="bold red")
116-
for idx, question_data in enumerate(questions_data): # Printing all the questions. The active question is printed GREEN.
117+
for idx, question_data in enumerate(questions_data):
117118
if question_posx == idx:
118119
console.print("[green]{}. {} | {}".format(idx+1, question_data[0], question_data[1]))
119120
else:
120121
console.print("{}. {} | {}".format(idx+1, question_data[0], question_data[1]))
121-
122122
console.rule("[bold blue] Answer of question {}".format(question_posx+1), style="bold red")
123-
current_question_id = questions_data[question_posx][2] # Gets the question_id of active question
124-
if(downloaded_questions_cache[current_question_id]): # Searches for the id in cache. If present then prints it
123+
124+
# Gets the question_id of active question
125+
current_question_id = questions_data[question_posx][2]
126+
127+
# Searches for the id in cache. If present then prints it
128+
if(downloaded_questions_cache[current_question_id]):
125129
output_content = downloaded_questions_cache[current_question_id]
126130
for output_index, output_text in enumerate(output_content):
127131
"""
@@ -140,9 +144,10 @@ def get_ans(self, questions_list):
140144
continue
141145

142146
console.print(output_text)
143-
144-
else: # If the cache has no entry for the said question id, the downloads the answer
145-
try: # and makes an entry for it in the said format [Line 110] and restarts the loop.
147+
# If the cache has no entry for the said question id, then downloads the answer
148+
# and makes an entry for it in the said format [Line 110] and restarts the loop.
149+
else:
150+
try:
146151
resp = requests.get(
147152
f"{self.search_content_url}/2.2/questions/{current_question_id}/answers?order=desc&sort=votes&site=stackoverflow&filter=!--1nZwsgqvRX"
148153
)
@@ -157,9 +162,10 @@ def get_ans(self, questions_list):
157162
continue
158163

159164
console.rule("[bold blue]", style="bold red", align="right")
165+
# Asks the user for next question number. Makes it the active question and loop restarts
160166
while True:
161-
posx = int(input("Enter the question number you want to view (Press 0 to quit): ")) - 1 # Asks the user for next question number. Makes it the active question and loop restarts
162-
if (posx == -1): # Press 0 to exit
167+
posx = int(input("Enter the question number you want to view (Press 0 to quit): ")) - 1
168+
if (posx == -1):
163169
return
164170
elif (0<=posx<len(questions_data)):
165171
question_posx = posx

0 commit comments

Comments
 (0)