Spaces:
Running
Running
Update history_manager.py
Browse files- history_manager.py +0 -67
history_manager.py
CHANGED
@@ -11,73 +11,6 @@ class UserHistoryManager:
|
|
11 |
print(f"Initializing UserHistoryManager with file: {os.path.abspath(self.history_file)}")
|
12 |
self._init_file()
|
13 |
|
14 |
-
# def _init_file(self):
|
15 |
-
# """初始化JSON檔案"""
|
16 |
-
# try:
|
17 |
-
# if not os.path.exists(self.history_file):
|
18 |
-
# print(f"Creating new history file: {self.history_file}")
|
19 |
-
# with open(self.history_file, 'w', encoding='utf-8') as f:
|
20 |
-
# json.dump([], f)
|
21 |
-
# else:
|
22 |
-
# print(f"History file exists: {self.history_file}")
|
23 |
-
# # 驗證檔案內容
|
24 |
-
# with open(self.history_file, 'r', encoding='utf-8') as f:
|
25 |
-
# data = json.load(f)
|
26 |
-
# print(f"Current history entries: {len(data)}")
|
27 |
-
# except Exception as e:
|
28 |
-
# print(f"Error in _init_file: {str(e)}")
|
29 |
-
# print(traceback.format_exc())
|
30 |
-
|
31 |
-
|
32 |
-
# def save_history(self, user_preferences: dict = None, results: list = None, search_type: str = "criteria", description: str = None) -> bool:
|
33 |
-
# """
|
34 |
-
# Save search history with proper timestamp handling.
|
35 |
-
|
36 |
-
# Args:
|
37 |
-
# user_preferences: User's search preferences
|
38 |
-
# results: List of breed recommendations
|
39 |
-
# search_type: Type of search performed
|
40 |
-
# description: Search description if applicable
|
41 |
-
|
42 |
-
# Returns:
|
43 |
-
# bool: Success status of save operation
|
44 |
-
# """
|
45 |
-
# try:
|
46 |
-
# # Initialize timezone and current time
|
47 |
-
# taipei_tz = pytz.timezone('Asia/Taipei')
|
48 |
-
# current_time = datetime.now(taipei_tz)
|
49 |
-
|
50 |
-
# # Create history entry with timestamp
|
51 |
-
# history_entry = {
|
52 |
-
# "timestamp": current_time.strftime("%Y-%m-%d %H:%M:%S"),
|
53 |
-
# "search_type": search_type,
|
54 |
-
# "results": results
|
55 |
-
# }
|
56 |
-
|
57 |
-
# # Add preferences to history entry if provided
|
58 |
-
# if user_preferences:
|
59 |
-
# history_entry["preferences"] = user_preferences
|
60 |
-
|
61 |
-
# # Read existing history
|
62 |
-
# with open(self.history_file, 'r', encoding='utf-8') as f:
|
63 |
-
# history = json.load(f)
|
64 |
-
|
65 |
-
# # Add new entry and maintain history limit
|
66 |
-
# history.append(history_entry)
|
67 |
-
# if len(history) > 20: # Keep last 20 entries
|
68 |
-
# history = history[-20:]
|
69 |
-
|
70 |
-
# # Save updated history
|
71 |
-
# with open(self.history_file, 'w', encoding='utf-8') as f:
|
72 |
-
# json.dump(history, f, ensure_ascii=False, indent=2)
|
73 |
-
|
74 |
-
# return True
|
75 |
-
|
76 |
-
# except Exception as e:
|
77 |
-
# print(f"Error saving history: {str(e)}")
|
78 |
-
# return False
|
79 |
-
|
80 |
-
|
81 |
def _init_file(self):
|
82 |
"""初始化JSON檔案"""
|
83 |
try:
|
|
|
11 |
print(f"Initializing UserHistoryManager with file: {os.path.abspath(self.history_file)}")
|
12 |
self._init_file()
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def _init_file(self):
|
15 |
"""初始化JSON檔案"""
|
16 |
try:
|