@@ -26,33 +26,39 @@ def __init__(self, arguments):
2626
2727 def search_args (self ):
2828 if self .arguments .search :
29- queries = ["What do you want to search" , "Tags" ]
30- query_solutions = []
31-
32- # ask quesiton
33- for each_query in queries :
34- # Be careful if there are
35- # KeyBpard Interupts or EOErrors
36- try :
37- prompt = Prompt (str (each_query )).prompt ()
38- except :
39- sys .exit ()
40-
41- query_solutions .append (prompt )
42-
43- question , tags = query_solutions [0 ], query_solutions [1 ]
44- json_output = self .utility_object .make_request (question , tags )
45- questions = self .utility_object .get_que (json_output )
46- if questions == []:
47- # evoke an error
48- search_error = SearchError ("No answer found" ,
49- "Please try reddit" )
50- else :
51- self .utility_object .get_ans (questions )
29+ self .search_for_results ()
5230
5331 elif self .arguments .new :
5432 url = "https://stackoverflow.com/questions/ask"
5533 if type (self .arguments .new ) == str :
5634 webbrowser .open (f"{ url } ?title={ self .arguments .new } " )
5735 else :
5836 webbrowser .open (url )
37+
38+ def search_for_results (self , save = False ):
39+ queries = ["What do you want to search" , "Tags" ]
40+ query_solutions = []
41+
42+ # ask quesiton
43+ for each_query in queries :
44+ # Be careful if there are
45+ # KeyBpard Interupts or EOErrors
46+ try :
47+ prompt = Prompt (str (each_query )).prompt ()
48+ except :
49+ sys .exit ()
50+
51+ query_solutions .append (prompt )
52+
53+ question , tags = query_solutions [0 ], query_solutions [1 ]
54+ json_output = self .utility_object .make_request (question , tags )
55+ questions = self .utility_object .get_que (json_output )
56+ if questions == []:
57+ # evoke an error
58+ search_error = SearchError ("No answer found" ,
59+ "Please try reddit" )
60+ else :
61+ data = self .utility_object .get_ans (questions )
62+
63+ if save :
64+ SaveSearchResults (data )
0 commit comments