VietCat commited on
Commit
6936c62
·
1 Parent(s): 35c4977

quick fix timestamp

Browse files
Files changed (1) hide show
  1. app/sheets.py +7 -7
app/sheets.py CHANGED
@@ -71,7 +71,7 @@ class SheetsClient:
71
  def get_conversation_history(self, user_id: str, page_id: str) -> List[Dict[str, Any]]:
72
  """Lấy lịch sử hội thoại từ sheet, đảm bảo so sánh kiểu dữ liệu an toàn."""
73
  # --- THÊM LOG ĐỂ DEBUG ---
74
- logger.debug(f"[get_conversation_history] Bắt đầu lấy lịch sử cho user_id: '{user_id}' và page_id: '{page_id}'")
75
  try:
76
  if not self.service:
77
  self.authenticate()
@@ -87,7 +87,7 @@ class SheetsClient:
87
  logger.warning(f"[get_conversation_history] Không tìm thấy dữ liệu hoặc chỉ có header trong sheet. Tổng số dòng: {len(values)}")
88
  return []
89
 
90
- logger.debug(f"[get_conversation_history] Đã lấy được {len(values)} dòng từ sheet.")
91
  header = values[0]
92
 
93
  for i, row in enumerate(values[1:], start=1):
@@ -97,13 +97,13 @@ class SheetsClient:
97
  sheet_recipient_id = row_data.get('recipient_id', 'N/A')
98
  sheet_page_id = row_data.get('page_id', 'N/A')
99
 
100
- logger.trace(f"[get_conversation_history] Đang xử lý dòng {i+1}: recipient_id='{sheet_recipient_id}', page_id='{sheet_page_id}'")
101
 
102
  is_recipient_match = str(sheet_recipient_id) == str(user_id)
103
  is_page_match = str(sheet_page_id) == str(page_id)
104
 
105
  if is_recipient_match and is_page_match:
106
- logger.success(f"[get_conversation_history] >>> TÌM THẤY DÒNG KHỚP tại dòng {i+1}!")
107
  try:
108
  timestamps_raw = json.loads(row_data.get('timestamp', '[]'))
109
  timestamps = _flatten_and_unique_timestamps(timestamps_raw)
@@ -117,11 +117,11 @@ class SheetsClient:
117
  else:
118
  # Log lý do không khớp
119
  if not is_recipient_match:
120
- logger.trace(f"[get_conversation_history] Dòng {i+1} không khớp: recipient_id (sheet: '{sheet_recipient_id}', input: '{user_id}')")
121
  if not is_page_match:
122
- logger.trace(f"[get_conversation_history] Dòng {i+1} không khớp: page_id (sheet: '{sheet_page_id}', input: '{page_id}')")
123
 
124
- logger.debug(f"[get_conversation_history] Hoàn tất xử lý. Tìm thấy {len(history)} bản ghi lịch sử.")
125
  return history
126
  except Exception as e:
127
  logger.error(f"Error getting conversation history: {e}", exc_info=True)
 
71
  def get_conversation_history(self, user_id: str, page_id: str) -> List[Dict[str, Any]]:
72
  """Lấy lịch sử hội thoại từ sheet, đảm bảo so sánh kiểu dữ liệu an toàn."""
73
  # --- THÊM LOG ĐỂ DEBUG ---
74
+ logger.info(f"[get_conversation_history] Bắt đầu lấy lịch sử cho user_id: '{user_id}' và page_id: '{page_id}'")
75
  try:
76
  if not self.service:
77
  self.authenticate()
 
87
  logger.warning(f"[get_conversation_history] Không tìm thấy dữ liệu hoặc chỉ có header trong sheet. Tổng số dòng: {len(values)}")
88
  return []
89
 
90
+ logger.info(f"[get_conversation_history] Đã lấy được {len(values)} dòng từ sheet.")
91
  header = values[0]
92
 
93
  for i, row in enumerate(values[1:], start=1):
 
97
  sheet_recipient_id = row_data.get('recipient_id', 'N/A')
98
  sheet_page_id = row_data.get('page_id', 'N/A')
99
 
100
+ logger.info(f"[get_conversation_history] Đang xử lý dòng {i+1}: recipient_id='{sheet_recipient_id}', page_id='{sheet_page_id}'")
101
 
102
  is_recipient_match = str(sheet_recipient_id) == str(user_id)
103
  is_page_match = str(sheet_page_id) == str(page_id)
104
 
105
  if is_recipient_match and is_page_match:
106
+ logger.info(f"[get_conversation_history] >>> TÌM THẤY DÒNG KHỚP tại dòng {i+1}!")
107
  try:
108
  timestamps_raw = json.loads(row_data.get('timestamp', '[]'))
109
  timestamps = _flatten_and_unique_timestamps(timestamps_raw)
 
117
  else:
118
  # Log lý do không khớp
119
  if not is_recipient_match:
120
+ logger.info(f"[get_conversation_history] Dòng {i+1} không khớp: recipient_id (sheet: '{sheet_recipient_id}', input: '{user_id}')")
121
  if not is_page_match:
122
+ logger.info(f"[get_conversation_history] Dòng {i+1} không khớp: page_id (sheet: '{sheet_page_id}', input: '{page_id}')")
123
 
124
+ logger.info(f"[get_conversation_history] Hoàn tất xử lý. Tìm thấy {len(history)} bản ghi lịch sử.")
125
  return history
126
  except Exception as e:
127
  logger.error(f"Error getting conversation history: {e}", exc_info=True)