Skip to content

Commit 3d037fe

Browse files
committed
Edited the search() class
1 parent 8c5dbc1 commit 3d037fe

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

src/arguments/search.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/arguments/utility.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys as sys
55

66
from .error import SearchError
7+
from .save import SaveSearchResults
78
from .markdown import MarkdownRenderer
89

910
console = Console()
@@ -44,7 +45,7 @@ def get_que(self, json_data):
4445
return que_id
4546

4647
def get_ans(self, questions_list):
47-
# ans = []
48+
ans = []
4849
for questions in range(1):
4950
try:
5051
resp = requests.get(
@@ -83,3 +84,5 @@ def get_ans(self, questions_list):
8384
continue
8485

8586
console.print(output_text)
87+
ans.append(json_ans_data["items"])
88+
return ans

0 commit comments

Comments
 (0)