|
@@ -283,8 +283,6 @@ def _get_answer(args, links):
|
|
|
link = get_link_at_pos(links, args['pos'])
|
|
|
if not link:
|
|
|
return False
|
|
|
- if args.get('link'):
|
|
|
- return link
|
|
|
|
|
|
cache_key = link
|
|
|
page = cache.get(link)
|
|
@@ -394,6 +392,27 @@ def _clear_cache():
|
|
|
def _is_help_query(query: str):
|
|
|
return any([query.lower() == help_query for help_query in SUPPORTED_HELP_QUERIES])
|
|
|
|
|
|
+def _parse_json(res, args):
|
|
|
+ """
|
|
|
+ @res: json object with answers and metadata
|
|
|
+ @args: command-line arguments (used for parsing)
|
|
|
+ returns: formated string of text ready to be printed
|
|
|
+ """
|
|
|
+ res = json.loads(res)
|
|
|
+ if "error" in res:
|
|
|
+ return res["error"]
|
|
|
+
|
|
|
+ spliter_length = 80
|
|
|
+ answer_spliter = '\n' + '=' * spliter_length + '\n\n'
|
|
|
+
|
|
|
+ formated_answers = []
|
|
|
+ for answer in res["answers"]:
|
|
|
+
|
|
|
+ next_ans = answer["answer"]
|
|
|
+ if args["link"]: # if we only want links
|
|
|
+ next_ans = answer["link"]
|
|
|
+
|
|
|
+ formated_answers.append(next_ans)
|
|
|
|
|
|
def _get_help_instructions():
|
|
|
instruction_splitter = build_splitter(' ', 60)
|