Spaces:
Sleeping
Sleeping
ichieh commited on
Commit ·
e2df47d
1
Parent(s): b2c849d
fix: 修正日期格式處理邏輯
Browse files1. 正確處理 ISO 格式的時間
2. 移除多餘的日誌註釋
app.py
CHANGED
|
@@ -143,9 +143,9 @@ with app.app_context():
|
|
| 143 |
print("沒有桌子資料,嘗試從 Google Sheets 恢復資料...")
|
| 144 |
try:
|
| 145 |
response = requests.get(app.config['SETTINGS_SCRIPT_URL'])
|
| 146 |
-
print(f"Google Sheets 回應狀態碼: {response.status_code}")
|
| 147 |
data = response.json()
|
| 148 |
-
print(f"Google Sheets 回應內容: {data}")
|
| 149 |
|
| 150 |
if data.get('success'):
|
| 151 |
# 首先恢復設定
|
|
@@ -172,8 +172,9 @@ with app.app_context():
|
|
| 172 |
|
| 173 |
for participant_data in participants:
|
| 174 |
try:
|
| 175 |
-
|
| 176 |
-
|
|
|
|
| 177 |
|
| 178 |
participant = Participant(
|
| 179 |
nickname=participant_data['nickname'],
|
|
@@ -292,7 +293,7 @@ def update_settings():
|
|
| 292 |
}
|
| 293 |
}
|
| 294 |
|
| 295 |
-
print(f"Sending settings to Google Sheets: {settings_data}")
|
| 296 |
|
| 297 |
try:
|
| 298 |
response = requests.post(
|
|
@@ -300,7 +301,7 @@ def update_settings():
|
|
| 300 |
json=settings_data,
|
| 301 |
timeout=10
|
| 302 |
)
|
| 303 |
-
print(f"Response from Google Sheets: {response.text}")
|
| 304 |
|
| 305 |
if not response.ok:
|
| 306 |
print(f"Failed to sync settings to Google Sheets. Status: {response.status_code}")
|
|
@@ -382,13 +383,9 @@ def restore_data():
|
|
| 382 |
print(f"找到 {len(participants_data)} 個參與者資料")
|
| 383 |
|
| 384 |
for participant_data in participants_data:
|
| 385 |
-
#
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
created_at = created_at - timedelta(hours=8) # 轉換回 UTC 時間
|
| 389 |
-
except (ValueError, KeyError) as e:
|
| 390 |
-
print(f"時間解析錯誤: {str(e)}")
|
| 391 |
-
created_at = datetime.utcnow()
|
| 392 |
|
| 393 |
try:
|
| 394 |
participant = Participant(
|
|
@@ -508,9 +505,9 @@ def delete_participant(participant_id):
|
|
| 508 |
@app.route('/api/tables')
|
| 509 |
def get_tables():
|
| 510 |
try:
|
| 511 |
-
print("正在獲取桌次資料...")
|
| 512 |
tables = Table.query.order_by(Table.id).all()
|
| 513 |
-
print(f"找到 {len(tables)} 張桌子")
|
| 514 |
|
| 515 |
result = [{
|
| 516 |
'id': table.id,
|
|
@@ -525,10 +522,10 @@ def get_tables():
|
|
| 525 |
} for p in sorted(table.participants, key=lambda x: (not x.is_table_leader, x.created_at))]
|
| 526 |
} for table in tables]
|
| 527 |
|
| 528 |
-
print("桌次資料獲取成功")
|
| 529 |
return jsonify(result)
|
| 530 |
except Exception as e:
|
| 531 |
-
print(f"獲取桌次資料時出錯: {str(e)}")
|
| 532 |
db.session.rollback()
|
| 533 |
return jsonify({'error': str(e)}), 500
|
| 534 |
|
|
|
|
| 143 |
print("沒有桌子資料,嘗試從 Google Sheets 恢復資料...")
|
| 144 |
try:
|
| 145 |
response = requests.get(app.config['SETTINGS_SCRIPT_URL'])
|
| 146 |
+
print(f"Google Sheets 回應狀態碼: {response.status_code}")
|
| 147 |
data = response.json()
|
| 148 |
+
print(f"Google Sheets 回應內容: {data}")
|
| 149 |
|
| 150 |
if data.get('success'):
|
| 151 |
# 首先恢復設定
|
|
|
|
| 172 |
|
| 173 |
for participant_data in participants:
|
| 174 |
try:
|
| 175 |
+
# 處理 ISO 格式的時間
|
| 176 |
+
created_at_str = participant_data['created_at'].replace('T', ' ').replace('.000Z', '')
|
| 177 |
+
created_at = datetime.strptime(created_at_str, '%Y-%m-%d %H:%M:%S')
|
| 178 |
|
| 179 |
participant = Participant(
|
| 180 |
nickname=participant_data['nickname'],
|
|
|
|
| 293 |
}
|
| 294 |
}
|
| 295 |
|
| 296 |
+
print(f"Sending settings to Google Sheets: {settings_data}")
|
| 297 |
|
| 298 |
try:
|
| 299 |
response = requests.post(
|
|
|
|
| 301 |
json=settings_data,
|
| 302 |
timeout=10
|
| 303 |
)
|
| 304 |
+
print(f"Response from Google Sheets: {response.text}")
|
| 305 |
|
| 306 |
if not response.ok:
|
| 307 |
print(f"Failed to sync settings to Google Sheets. Status: {response.status_code}")
|
|
|
|
| 383 |
print(f"找到 {len(participants_data)} 個參與者資料")
|
| 384 |
|
| 385 |
for participant_data in participants_data:
|
| 386 |
+
# 處理 ISO 格式的時間
|
| 387 |
+
created_at_str = participant_data['created_at'].replace('T', ' ').replace('.000Z', '')
|
| 388 |
+
created_at = datetime.strptime(created_at_str, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
|
| 390 |
try:
|
| 391 |
participant = Participant(
|
|
|
|
| 505 |
@app.route('/api/tables')
|
| 506 |
def get_tables():
|
| 507 |
try:
|
| 508 |
+
print("正在獲取桌次資料...")
|
| 509 |
tables = Table.query.order_by(Table.id).all()
|
| 510 |
+
print(f"找到 {len(tables)} 張桌子")
|
| 511 |
|
| 512 |
result = [{
|
| 513 |
'id': table.id,
|
|
|
|
| 522 |
} for p in sorted(table.participants, key=lambda x: (not x.is_table_leader, x.created_at))]
|
| 523 |
} for table in tables]
|
| 524 |
|
| 525 |
+
print("桌次資料獲取成功")
|
| 526 |
return jsonify(result)
|
| 527 |
except Exception as e:
|
| 528 |
+
print(f"獲取桌次資料時出錯: {str(e)}")
|
| 529 |
db.session.rollback()
|
| 530 |
return jsonify({'error': str(e)}), 500
|
| 531 |
|