Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,6 +42,7 @@ def get_gsheet_client():
|
|
| 42 |
client = gspread.authorize(creds)
|
| 43 |
return client
|
| 44 |
|
|
|
|
| 45 |
# ===== Save to Google Sheets =====
|
| 46 |
# ===== Save to Google Sheets =====
|
| 47 |
def save_to_gsheet(name, student_id, major, prediction, sheet_name="Trang tính1"):
|
|
@@ -49,8 +50,20 @@ def save_to_gsheet(name, student_id, major, prediction, sheet_name="Trang tính1
|
|
| 49 |
now = datetime.now()
|
| 50 |
current_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# Create a data row to insert into the sheet
|
| 53 |
-
data_row = [name, student_id, major,
|
| 54 |
|
| 55 |
# Connect to Google Sheets
|
| 56 |
client = get_gsheet_client()
|
|
@@ -59,9 +72,14 @@ def save_to_gsheet(name, student_id, major, prediction, sheet_name="Trang tính1
|
|
| 59 |
sheet_id = "1i7bDNvLVLXN93_e-FN0JLzpg1jb64Z_aEuyPjIfwbdQ" # Use your actual ID here
|
| 60 |
sheet = client.open_by_key(sheet_id).worksheet(sheet_name)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# Append data to the sheet
|
| 63 |
sheet.append_row(data_row)
|
| 64 |
|
|
|
|
| 65 |
# ===== List all sheet names =====
|
| 66 |
# def list_sheet_names(sheet_id):
|
| 67 |
# client = get_gsheet_client()
|
|
|
|
| 42 |
client = gspread.authorize(creds)
|
| 43 |
return client
|
| 44 |
|
| 45 |
+
# ===== Save to Google Sheets =====
|
| 46 |
# ===== Save to Google Sheets =====
|
| 47 |
# ===== Save to Google Sheets =====
|
| 48 |
def save_to_gsheet(name, student_id, major, prediction, sheet_name="Trang tính1"):
|
|
|
|
| 50 |
now = datetime.now()
|
| 51 |
current_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
| 52 |
|
| 53 |
+
# Convert prediction to the proper result in Vietnamese
|
| 54 |
+
if isinstance(prediction, np.ndarray):
|
| 55 |
+
prediction = prediction.tolist() # Convert ndarray to list
|
| 56 |
+
else:
|
| 57 |
+
prediction = str(prediction) # Ensure it's a string if it's not a list
|
| 58 |
+
|
| 59 |
+
# Convert prediction to "Đúng hạn" or "Không đúng hạn"
|
| 60 |
+
if prediction == 1:
|
| 61 |
+
prediction_result = "Đúng hạn"
|
| 62 |
+
else:
|
| 63 |
+
prediction_result = "Không đúng hạn"
|
| 64 |
+
|
| 65 |
# Create a data row to insert into the sheet
|
| 66 |
+
data_row = [name, student_id, major, prediction_result, current_time]
|
| 67 |
|
| 68 |
# Connect to Google Sheets
|
| 69 |
client = get_gsheet_client()
|
|
|
|
| 72 |
sheet_id = "1i7bDNvLVLXN93_e-FN0JLzpg1jb64Z_aEuyPjIfwbdQ" # Use your actual ID here
|
| 73 |
sheet = client.open_by_key(sheet_id).worksheet(sheet_name)
|
| 74 |
|
| 75 |
+
# Check if columns are set, if not, add them as headers
|
| 76 |
+
if not sheet.get_all_values(): # If the sheet is empty
|
| 77 |
+
sheet.append_row(["STT", "Họ và tên", "MSV", "Khoa", "Dự báo", "Thời gian"]) # Create headers
|
| 78 |
+
|
| 79 |
# Append data to the sheet
|
| 80 |
sheet.append_row(data_row)
|
| 81 |
|
| 82 |
+
|
| 83 |
# ===== List all sheet names =====
|
| 84 |
# def list_sheet_names(sheet_id):
|
| 85 |
# client = get_gsheet_client()
|