Spaces:
Running
Running
Update history_manager.py
Browse files- history_manager.py +40 -33
history_manager.py
CHANGED
@@ -29,45 +29,52 @@ class UserHistoryManager:
|
|
29 |
print(f"Error in _init_file: {str(e)}")
|
30 |
print(traceback.format_exc())
|
31 |
|
32 |
-
def save_history(self, user_preferences: dict = None, results: list = None, search_type: str = "criteria", description: str = None) -> bool:
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
def get_history(self) -> list:
|
73 |
"""獲取搜尋歷史"""
|
|
|
29 |
print(f"Error in _init_file: {str(e)}")
|
30 |
print(traceback.format_exc())
|
31 |
|
32 |
+
# def save_history(self, user_preferences: dict = None, results: list = None, search_type: str = "criteria", description: str = None) -> bool:
|
33 |
+
# """
|
34 |
+
# 儲存搜尋歷史,支援兩種類型的搜尋
|
35 |
+
# Args:
|
36 |
+
# user_preferences: dict, 使用者偏好設定 (用於 criteria 搜尋)
|
37 |
+
# results: list, 推薦結果
|
38 |
+
# search_type: str, 搜尋類型 ("criteria" 或 "description")
|
39 |
+
# description: str, 使用者輸入的描述 (用於 description 搜尋)
|
40 |
+
# """
|
41 |
+
# try:
|
42 |
+
# taipei_tz = pytz.timezone('Asia/Taipei')
|
43 |
+
# taipei_time = datetime.now(taipei_tz)
|
44 |
|
45 |
+
# history_entry = {
|
46 |
+
# "timestamp": taipei_time.strftime("%Y-%m-%d %H:%M:%S"),
|
47 |
+
# "search_type": search_type,
|
48 |
+
# "results": results
|
49 |
+
# }
|
50 |
|
51 |
+
# # 根據搜尋類型添加不同的資訊
|
52 |
+
# if search_type == "criteria":
|
53 |
+
# history_entry["preferences"] = user_preferences
|
54 |
+
# else: # description
|
55 |
+
# history_entry["description"] = description
|
56 |
|
57 |
+
# with open(self.history_file, 'r', encoding='utf-8') as f:
|
58 |
+
# history = json.load(f)
|
59 |
|
60 |
+
# history.append(history_entry)
|
61 |
+
# if len(history) > 20:
|
62 |
+
# history = history[-20:]
|
63 |
|
64 |
+
# with open(self.history_file, 'w', encoding='utf-8') as f:
|
65 |
+
# json.dump(history, f, ensure_ascii=False, indent=2)
|
66 |
|
67 |
+
# return True
|
68 |
+
# except Exception as e:
|
69 |
+
# print(f"Error saving history: {str(e)}")
|
70 |
+
# return False
|
71 |
+
|
72 |
+
def save_history(self, user_preferences: dict = None, results: list = None, search_type: str = "criteria", description: str = None) -> bool:
|
73 |
+
history_entry = {
|
74 |
+
"timestamp": taipei_time.strftime("%Y-%m-%d %H:%M:%S"),
|
75 |
+
"search_type": search_type,
|
76 |
+
"results": results
|
77 |
+
}
|
78 |
|
79 |
def get_history(self) -> list:
|
80 |
"""獲取搜尋歷史"""
|