VietCat commited on
Commit
97d85f7
·
1 Parent(s): 6535336

fix duplicate message

Browse files
Files changed (1) hide show
  1. app/sheets.py +7 -7
app/sheets.py CHANGED
@@ -226,16 +226,17 @@ class SheetsClient:
226
  else:
227
  # Update existing conversation
228
  row_index = None
229
-
230
  for i, row in enumerate(values):
 
 
 
231
  if row[0] == conversation_id:
232
  row_index = i
233
  break
234
-
235
  if row_index is not None:
236
- # Lấy dữ liệu dòng hiện tại
 
237
  current_row = values[row_index]
238
- # Đảm bảo đủ 13 cột (thêm processing)
239
  while len(current_row) < 13:
240
  current_row.append("")
241
  # Tạo dòng mới với giá trị mới nếu có, giữ nguyên nếu không
@@ -253,7 +254,7 @@ class SheetsClient:
253
  timestamp if timestamp else current_row[10],
254
  str(is_done).lower() if is_done is not None else current_row[11]
255
  ]
256
- update_range = f"{SHEET_RANGE.split('!')[0]}!A{row_index + 1}"
257
  body = {
258
  'values': [new_row]
259
  }
@@ -263,13 +264,12 @@ class SheetsClient:
263
  valueInputOption='RAW',
264
  body=body
265
  ).execute()
266
-
267
  changed_cols = []
268
  col_names = ['conversation_id','command','content','attachments','user_id','page_id','message','vehicle','action','purpose','timestamp','is_done']
269
  for idx, (old, new) in enumerate(zip(current_row, new_row)):
270
  if old != new:
271
  changed_cols.append(col_names[idx])
272
- logger.info(f"Cập nhật conversation: {conversation_id} tại dòng {row_index+1} | Cột cập nhật: {changed_cols} | Giá trị mới: {dict(zip(col_names, new_row))}")
273
 
274
  # Return the updated conversation data
275
  return {
 
226
  else:
227
  # Update existing conversation
228
  row_index = None
 
229
  for i, row in enumerate(values):
230
+ # Bỏ qua header nếu có
231
+ if row and row[0] == 'conversation_id':
232
+ continue
233
  if row[0] == conversation_id:
234
  row_index = i
235
  break
 
236
  if row_index is not None:
237
+ # Nếu sheet có header ở dòng 1, thì dòng dữ liệu đầu tiên là dòng 2
238
+ sheet_row_number = row_index + 1 # +1 vì values đã bao gồm header ở index 0
239
  current_row = values[row_index]
 
240
  while len(current_row) < 13:
241
  current_row.append("")
242
  # Tạo dòng mới với giá trị mới nếu có, giữ nguyên nếu không
 
254
  timestamp if timestamp else current_row[10],
255
  str(is_done).lower() if is_done is not None else current_row[11]
256
  ]
257
+ update_range = f"{SHEET_RANGE.split('!')[0]}!A{sheet_row_number}"
258
  body = {
259
  'values': [new_row]
260
  }
 
264
  valueInputOption='RAW',
265
  body=body
266
  ).execute()
 
267
  changed_cols = []
268
  col_names = ['conversation_id','command','content','attachments','user_id','page_id','message','vehicle','action','purpose','timestamp','is_done']
269
  for idx, (old, new) in enumerate(zip(current_row, new_row)):
270
  if old != new:
271
  changed_cols.append(col_names[idx])
272
+ logger.info(f"Cập nhật conversation: {conversation_id} tại dòng {sheet_row_number} | Cột cập nhật: {changed_cols} | Giá trị mới: {dict(zip(col_names, new_row))}")
273
 
274
  # Return the updated conversation data
275
  return {