@@ -43,7 +43,10 @@ def __init__(self):
4343
4444 @property
4545 def playbook_path (self ):
46- # Create an environment variable 'DYNAMIC' containing the path of dynamic_playbook.json and returns it
46+ """
47+ Create an environment variable 'DYNAMIC'
48+ containing the path of dynamic_playbook.json and returns it
49+ """
4750 if not os .getenv (self .key ):
4851 if (sys .platform == 'linux' ):
4952 os .environ [self .key ] = os .path .join (self .linux_path , self .file_name )
@@ -134,19 +137,28 @@ def delete_from_playbook(self, stackoverflow_object, question_id):
134137 def display_panel (self ):
135138 playbook_data = self .playbook_content
136139 if (len (playbook_data ['items_stackoverflow' ]) == 0 ):
137- SearchError ("You have no entries in the playbook" , "Browse and save entries in playbook with 'p' key" )
140+ SearchError ("You have no entries in the playbook" ,
141+ "Browse and save entries in playbook with 'p' key" )
138142 sys .exit ()
139- # Creates QuestionPanelStackoverflow object, populates its question_data and answer_data and displays it
143+ # Creates QuestionPanelStackoverflow object
144+ # populates its question_data and answer_data and displays it
140145 question_panel = QuestionsPanelStackoverflow ()
141146 for item in playbook_data ['items_stackoverflow' ]:
142- question_panel .questions_data .append ( [item ['question_title' ], item ['question_id' ], item ['question_link' ]] )
147+ question_panel .questions_data .append ( [item ['question_title' ],
148+ item ['question_id' ],
149+ item ['question_link' ]] )
143150 question_panel .answer_data [item ['question_id' ]] = item ['answer_body' ]
144151 question_panel .display_panel ([], playbook = True )
145152
146153class QuestionsPanelStackoverflow ():
147154 def __init__ (self ):
148- self .questions_data = [] # list( list( question_title, question_id, question_link )... )
149- self .answer_data = defaultdict (lambda : False ) # dict( question_id:list( body, link )) corresponding to self.questions_data
155+ # list( list( question_title, question_id, question_link )... )
156+ self .questions_data = []
157+
158+ # dict( question_id:list( body, link ))
159+ # corresponding to self.questions_data
160+ self .answer_data = defaultdict (lambda : False )
161+
150162 self .line_color = "bold red"
151163 self .heading_color = "bold blue"
152164 self .utility = Utility ()
@@ -155,8 +167,9 @@ def __init__(self):
155167 def populate_question_data (self , questions_list ):
156168 """
157169 Function to populate question data property
158- Creates batch request to stackexchange API and to get question details of
159- questions with id in the list. Stores the returned data data in the following format:
170+ Creates batch request to stackexchange API and to get question
171+ details of questions with id in the list. Stores the returned
172+ data in the following format:
160173 list( list( question_title, question_link, question_id ) )
161174 """
162175 with console .status ("Getting the questions..." ):
@@ -168,7 +181,9 @@ def populate_question_data(self, questions_list):
168181 SearchError ("Search Failed" , "Try connecting to the internet" )
169182 sys .exit ()
170183 json_ques_data = resp .json ()
171- self .questions_data = [[item ['title' ].replace ('|' ,'' ), item ['question_id' ], item ['link' ]] for item in json_ques_data ["items" ]]
184+ self .questions_data = [[item ['title' ].replace ('|' ,'' ),
185+ item ['question_id' ], item ['link' ]]
186+ for item in json_ques_data ["items" ]]
172187
173188 def populate_answer_data (self , questions_list ):
174189 """
@@ -189,16 +204,19 @@ def populate_answer_data(self, questions_list):
189204 for item in json_ans_data ["items" ]:
190205 if not (self .answer_data [item ['question_id' ]]):
191206 self .answer_data [item ['question_id' ]] = item ['body_markdown' ]
192- # Sometimes the StackExchange API fails to deliver some answers. The below code is to fetch them
193- failed_ques_id = [question [1 ] for question in self .questions_data if not (self .answer_data [question [1 ]])]
207+ # Sometimes the StackExchange API fails to deliver some answers.
208+ # The below code is to fetch them
209+ failed_ques_id = [question [1 ] for question in self .questions_data
210+ if not (self .answer_data [question [1 ]])]
194211 if not (len (failed_ques_id ) == 0 ):
195212 self .populate_answer_data (failed_ques_id )
196213
197214 def return_formatted_ans (self , ques_id ):
198215 # This function uses uses Rich Markdown to format answers body.
199216 body_markdown = self .answer_data [int (ques_id )]
200217 body_markdown = str (body_markdown )
201- xml_markup_replacement = [("&" , "&" ), ("<" , "<" ), (">" , ">" ), (""" , "\" " ), ("'" , "\' " ), ("'" , "\' " )]
218+ xml_markup_replacement = [("&" , "&" ), ("<" , "<" ), (">" , ">" ),
219+ (""" , "\" " ), ("'" , "\' " ), ("'" , "\' " )]
202220 for convert_from , convert_to in xml_markup_replacement :
203221 body_markdown = body_markdown .replace (convert_from , convert_to )
204222 width = os .get_terminal_size ().columns
@@ -207,20 +225,32 @@ def return_formatted_ans(self, ques_id):
207225 with console .capture () as capture :
208226 console .print (markdown )
209227 highlighted = capture .get ()
210- if locale .getlocale ()[1 ] != 'UTF-8' :
211- box_replacement = [("─" , "-" ), ("═" ,"=" ), ("║" ,"|" ), ("│" , "|" ), ('┌' , '+' ), ("└" , "+" ), ("┐" , "+" ), ("┘" , "+" ), ("╔" , "+" ), ("╚" , "+" ), ("╗" ,"+" ), ("╝" , "+" ), ("•" ,"*" )]
228+ if not ('UTF' in locale .getlocale ()[1 ]):
229+ box_replacement = [("─" , "-" ), ("═" ,"=" ), ("║" ,"|" ), ("│" , "|" ),
230+ ('┌' , '+' ), ("└" , "+" ), ("┐" , "+" ), ("┘" , "+" ),
231+ ("╔" , "+" ), ("╚" , "+" ), ("╗" ,"+" ), ("╝" , "+" ), ("•" ,"*" )]
212232 for convert_from , convert_to in box_replacement :
213233 highlighted = highlighted .replace (convert_from , convert_to )
214234 return highlighted
215235
216236 def navigate_questions_panel (self , playbook = False ):
217237 # Code for navigating through the question panel
218- (message , instructions , keys ) = ('Playbook Questions' , ". Press 'd' to delete from playbook" , ('enter' , 'd' )) if (playbook ) else ('Relevant Questions' , ". Press 'p' to save in playbook" , ('p' , 'enter' ))
238+ if playbook :
239+ message = 'Playbook Questions'
240+ instructions = ". Press 'd' to delete from playbook"
241+ keys = ('enter' , 'd' )
242+ else :
243+ message = 'Relevant Questions'
244+ instructions = ". Press 'p' to save in playbook"
245+ keys = ('enter' , 'p' )
219246 console .rule ('[bold blue] {}' .format (message ), style = "bold red" )
220- console .print ("[yellow] Use arrow keys to navigate. 'q' or 'Esc' to quit. 'Enter' to open in a browser" + instructions )
247+ console .print ("[yellow] Use arrow keys to navigate. \
248+ 'q' or 'Esc' to quit. 'Enter' to open in a browser" +
249+ instructions )
221250 console .print ()
222251 options = ["|" .join (map (str , question )) for question in self .questions_data ]
223- question_menu = TerminalMenu (options , preview_command = self .return_formatted_ans , preview_size = 0.75 , accept_keys = keys )
252+ question_menu = TerminalMenu (options , preview_command = self .return_formatted_ans ,
253+ preview_size = 0.75 , accept_keys = keys )
224254 quitting = False
225255 while not (quitting ):
226256 options_index = question_menu .show ()
@@ -273,10 +303,15 @@ def get_batch_ans_url(self, ques_id_list):
273303
274304 def make_request (self , que , tag : str ):
275305 """
276- This function uses the requests library to make the rest api call to the stackexchange server.
277- :param que: The user questions that servers as a question in the api.
306+ This function uses the requests library to make
307+ the rest api call to the stackexchange server.
308+ :param que: The user questions that servers as
309+ a question in the api.
278310 :type que: String
279- :param tag: The tags that user wants for searching the relevant answers. For e.g. TypeError might be for multiple languages so is tag is used as "Python" then the api will return answers based on the tags and question.
311+ :param tag: The tags that user wants for searching the relevant
312+ answers. For e.g. TypeError might be for multiple
313+ languages so is tag is used as "Python" then the
314+ api will return answers based on the tags and question.
280315 :type tag: String
281316 :return: Json response from the api call.
282317 :rtype: Json format data
@@ -285,7 +320,8 @@ def make_request(self, que, tag: str):
285320 try :
286321 resp = requests .get (self .__get_search_url (que , tag ))
287322 except :
288- SearchError ("\U0001F613 Search Failed" , "\U0001F4BB Try connecting to the internet" )
323+ SearchError ("\U0001F613 Search Failed" ,
324+ "\U0001F4BB Try connecting to the internet" )
289325 sys .exit ()
290326 return resp .json ()
291327
@@ -314,19 +350,23 @@ def get_ans(self, questions_list):
314350 @classmethod
315351 def setCustomKey (self ):
316352 client_id = 20013
317-
318- # scopes possible values:
319- # read_inbox - access a user's global inbox
320- # no_expiry - access_token's with this scope do not expire
321- # write_access - perform write operations as a user
322- # private_info - access full history of a user's private actions on the site
353+ """
354+ scopes possible values:
355+ read_inbox - access a user's global inbox
356+ no_expiry - access_token's with this scope do not expire
357+ write_access - perform write operations as a user
358+ private_info - access full history of a user's private
359+ actions on the site
360+ """
323361 scopes = 'read_inbox'
324362
325363 authorization_url = 'https://stackoverflow.com/oauth/dialog'
326364 redirect_uri = 'https://stackexchange.com/oauth/login_success'
327365
328- # Create an OAuth session and open the auth_url in a browser for the user to authenticate
329- stackApps = OAuth2Session (client = MobileApplicationClient (client_id = client_id ), scope = scopes , redirect_uri = redirect_uri )
366+ # Create an OAuth session and open the auth_url in a browser
367+ # for the user to authenticate
368+ stackApps = OAuth2Session (client = MobileApplicationClient (client_id = client_id ),
369+ scope = scopes , redirect_uri = redirect_uri )
330370 auth_url , state = stackApps .authorization_url (authorization_url )
331371
332372 # Try to install web drivers for one of these browsers
@@ -340,7 +380,8 @@ def setCustomKey(self):
340380 try :
341381 driver = webdriver .Edge (EdgeChromiumDriverManager ().install ())
342382 except ValueError :
343- print ("You do not have one of these supported browsers: Chrome, Firefox, Edge" )
383+ print ("You do not have one of these supported browsers: \
384+ Chrome, Firefox, Edge" )
344385
345386 # Open auth_url in one of the supported browsers
346387 driver .get (auth_url )
0 commit comments