From 0a01146227437691759c4db328b5a2f3301dee91 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Tue, 30 Nov 2021 20:55:40 +0100 Subject: [PATCH] refact --- src/fime/task_completer.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/fime/task_completer.py b/src/fime/task_completer.py index f6db724..8d4064d 100644 --- a/src/fime/task_completer.py +++ b/src/fime/task_completer.py @@ -3,9 +3,8 @@ import sys import threading import traceback from enum import Enum, auto -from functools import reduce +from functools import reduce, partial from queue import Queue, Empty -from urllib.parse import urlparse, parse_qs try: from PySide6 import QtCore, QtWidgets @@ -90,20 +89,18 @@ class TaskCompleter(QtWidgets.QCompleter): ) with self.rif_counter_lock: self.rif_counter += 1 - future.add_done_callback(self.picker_response_callback) + future.add_done_callback(partial(self.picker_response_callback, self.text)) - def picker_response_callback(self, future): + def picker_response_callback(self, text, future): with self.rif_counter_lock: self.rif_counter -= 1 try: result = future.result() - parsed = urlparse(result.request.url) - response_text = parse_qs(parsed.query)["query"][0] issues = reduce(lambda x, y: x + (y["issues"]), result.json()["sections"], []) extracted = list(map(lambda x: f"{x['key']} {x['summaryText']}", issues)) if extracted: self.queue.put({ - "response_text": response_text, + "response_text": text, "result": extracted, }) else: @@ -132,20 +129,18 @@ class TaskCompleter(QtWidgets.QCompleter): ) with self.rif_counter_lock: self.rif_counter += 1 - future.add_done_callback(self.search_response_callback) + future.add_done_callback(partial(self.search_response_callback, self.text)) - def search_response_callback(self, future): + def search_response_callback(self, text, future): with self.rif_counter_lock: self.rif_counter -= 1 try: result = future.result() json_result = result.json() - parsed = urlparse(result.request.url) - response_text = parse_qs(parsed.query)["jql"][0].split()[2] if "issues" in json_result: extracted = list(map(lambda x: f"{x['key']} {x['fields']['summary']}", json_result["issues"])) self.queue.put({ - "response_text": response_text, + "response_text": text, "result": extracted, }) except Exception: