fix timestamp issue
Browse files- app/sheets.py +17 -5
app/sheets.py
CHANGED
|
@@ -152,14 +152,26 @@ class SheetsClient:
|
|
| 152 |
values = result.get('values', [])
|
| 153 |
# logger.info(f"[DEBUG] Gsheet values {values}")
|
| 154 |
# Đảm bảo timestamp là str
|
|
|
|
|
|
|
| 155 |
if timestamp is None:
|
| 156 |
-
|
| 157 |
-
|
|
|
|
| 158 |
# Chống trùng bản ghi dựa trên sender_id, page_id, timestamp
|
| 159 |
for row in values:
|
| 160 |
-
if len(row) >=
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
logger.info(f"Found duplicate conversation for user {recipient_id}, page {page_id}, timestamp {timestamp}")
|
| 164 |
return {
|
| 165 |
'conversation_id': row[0],
|
|
|
|
| 152 |
values = result.get('values', [])
|
| 153 |
# logger.info(f"[DEBUG] Gsheet values {values}")
|
| 154 |
# Đảm bảo timestamp là str
|
| 155 |
+
ts = datetime.now().isoformat()
|
| 156 |
+
# Đảm bảo timestamp luôn là list
|
| 157 |
if timestamp is None:
|
| 158 |
+
timestamp = []
|
| 159 |
+
elif not isinstance(timestamp, list):
|
| 160 |
+
timestamp = [timestamp]
|
| 161 |
# Chống trùng bản ghi dựa trên sender_id, page_id, timestamp
|
| 162 |
for row in values:
|
| 163 |
+
if len(row) >= 13:
|
| 164 |
+
try:
|
| 165 |
+
row_timestamps = json.loads(row[12]) if row[12] else []
|
| 166 |
+
except Exception:
|
| 167 |
+
row_timestamps = []
|
| 168 |
+
if not isinstance(row_timestamps, list):
|
| 169 |
+
row_timestamps = [row_timestamps]
|
| 170 |
+
if not isinstance(row_timestamps, list):
|
| 171 |
+
row_timestamps = [row_timestamps]
|
| 172 |
+
row_recipient_id = row[4]
|
| 173 |
+
row_page_id = row[5]
|
| 174 |
+
if (str(timestamp) in [str(ts) for ts in row_timestamps] and str(row_recipient_id) == str(recipient_id) and str(row_page_id) == str(page_id)):
|
| 175 |
logger.info(f"Found duplicate conversation for user {recipient_id}, page {page_id}, timestamp {timestamp}")
|
| 176 |
return {
|
| 177 |
'conversation_id': row[0],
|