@@ -32,6 +32,11 @@ def __init__(self):
3232 self .search_content_url = "https://api.stackexchange.com/"
3333
3434 def __get_search_url (self , question , tags ):
35+ """
36+ This function returns the url that contains all the custom
37+ data provided by the user such as tags and question, which
38+ can finally be used to get answers
39+ """
3540 return f"{ self .search_content_url } /2.2/search/advanced?order=desc&sort=relevance&tagged={ tags } &title={ question } &site=stackoverflow"
3641
3742 def make_request (self , que , tag : str ):
@@ -54,13 +59,32 @@ def make_request(self, que, tag: str):
5459 return resp .json ()
5560
5661 def get_que (self , json_data ):
62+ """
63+ This function returns the list of ids of the questions
64+ that have been answered, from the response that we get
65+ from the make_request function.
66+ """
5767 que_id = []
5868 for data in json_data ['items' ]:
5969 if data ["is_answered" ]:
6070 que_id .append (data ["question_id" ])
6171 return que_id
6272
6373 def get_ans (self , questions_list ):
74+ """
75+ This function prints the answer to the queries
76+ (question and tags) provided by the user. It does so
77+ in the following manner :
78+
79+ 1) Takes in account only th first question id from the
80+ list of question ids
81+
82+ 2) Tries to get a response from the url obtained by appending
83+ question id to the search_content_url variable
84+
85+ 3) Use the data received from the above request and loop
86+ through it to print the answer
87+ """
6488 ans = []
6589 for questions in range (1 ):
6690 try :
@@ -83,7 +107,7 @@ def get_ans(self, questions_list):
83107 for output_index , output_text in enumerate (output_content ):
84108 """
85109 Loop through the output_text and print the element
86- if it the last one, the text[0] is printed
110+ if it is the last one, the text[0] is printed
87111 along with text[-1]
88112
89113 if text is markdown , render the markdown
0 commit comments