Spaces:
Sleeping
Sleeping
ichieh commited on
Commit ·
389e379
1
Parent(s): a0158bf
Remove unused files
Browse files- init_db.py +0 -37
- sync_to_sheets.gs +0 -93
init_db.py
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
from app import app, db, Table
|
| 2 |
-
import os
|
| 3 |
-
|
| 4 |
-
def init_tables():
|
| 5 |
-
db_path = os.path.join(app.instance_path, 'event.db')
|
| 6 |
-
|
| 7 |
-
# 確保 instance 資料夾存在並設置權限
|
| 8 |
-
try:
|
| 9 |
-
os.makedirs(app.instance_path, exist_ok=True)
|
| 10 |
-
if not os.path.exists(db_path):
|
| 11 |
-
open(db_path, 'a').close()
|
| 12 |
-
os.chmod(app.instance_path, 0o777)
|
| 13 |
-
os.chmod(db_path, 0o666)
|
| 14 |
-
except OSError as e:
|
| 15 |
-
print(f"Error setting up database: {e}")
|
| 16 |
-
|
| 17 |
-
with app.app_context():
|
| 18 |
-
try:
|
| 19 |
-
# 確保所有表格都被創建
|
| 20 |
-
db.create_all()
|
| 21 |
-
|
| 22 |
-
# 清空現有的桌子
|
| 23 |
-
Table.query.delete()
|
| 24 |
-
|
| 25 |
-
# 創建10張桌子,每張可以坐8人
|
| 26 |
-
for i in range(1, 11):
|
| 27 |
-
table = Table(capacity=8, name=f'Table {i}')
|
| 28 |
-
db.session.add(table)
|
| 29 |
-
|
| 30 |
-
db.session.commit()
|
| 31 |
-
print("Tables initialized successfully!")
|
| 32 |
-
except Exception as e:
|
| 33 |
-
print(f"Error initializing tables: {e}")
|
| 34 |
-
db.session.rollback()
|
| 35 |
-
|
| 36 |
-
if __name__ == '__main__':
|
| 37 |
-
init_tables()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sync_to_sheets.gs
DELETED
|
@@ -1,93 +0,0 @@
|
|
| 1 |
-
// 設置您的應用程序 URL
|
| 2 |
-
const APP_URL = 'https://fromnowoncoding-eventinvite.hf.space/api/participants/export'; // Hugging Face Space URL
|
| 3 |
-
|
| 4 |
-
// 設置工作表名稱
|
| 5 |
-
const SHEET_NAME = '報名者資料';
|
| 6 |
-
|
| 7 |
-
// 設置表頭
|
| 8 |
-
const HEADERS = [
|
| 9 |
-
'桌號',
|
| 10 |
-
'座位容量',
|
| 11 |
-
'暱稱',
|
| 12 |
-
'Email',
|
| 13 |
-
'FB連結',
|
| 14 |
-
'自我介紹',
|
| 15 |
-
'報名時間'
|
| 16 |
-
];
|
| 17 |
-
|
| 18 |
-
function updateSpreadsheet() {
|
| 19 |
-
try {
|
| 20 |
-
// 獲取或創建工作表
|
| 21 |
-
const ss = SpreadsheetApp.getActiveSpreadsheet();
|
| 22 |
-
let sheet = ss.getSheetByName(SHEET_NAME);
|
| 23 |
-
if (!sheet) {
|
| 24 |
-
sheet = ss.insertSheet(SHEET_NAME);
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
// 清除現有資料
|
| 28 |
-
sheet.clear();
|
| 29 |
-
|
| 30 |
-
// 設置表頭
|
| 31 |
-
sheet.getRange(1, 1, 1, HEADERS.length).setValues([HEADERS]);
|
| 32 |
-
|
| 33 |
-
// 從應用程序獲取資料
|
| 34 |
-
const options = {
|
| 35 |
-
'muteHttpExceptions': true,
|
| 36 |
-
'method': 'get'
|
| 37 |
-
};
|
| 38 |
-
const response = UrlFetchApp.fetch(APP_URL, options);
|
| 39 |
-
|
| 40 |
-
// 檢查響應狀態
|
| 41 |
-
if (response.getResponseCode() !== 200) {
|
| 42 |
-
throw new Error('API request failed with status: ' + response.getResponseCode() +
|
| 43 |
-
'\nResponse: ' + response.getContentText());
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
const participants = JSON.parse(response.getContentText());
|
| 47 |
-
|
| 48 |
-
if (participants.length > 0) {
|
| 49 |
-
// 準備資料
|
| 50 |
-
const data = participants.map(p => [
|
| 51 |
-
p.table_name,
|
| 52 |
-
p.table_capacity,
|
| 53 |
-
p.nickname,
|
| 54 |
-
p.email,
|
| 55 |
-
p.fb_link || '',
|
| 56 |
-
p.introduction || '',
|
| 57 |
-
p.registration_time
|
| 58 |
-
]);
|
| 59 |
-
|
| 60 |
-
// 寫入資料
|
| 61 |
-
sheet.getRange(2, 1, data.length, HEADERS.length).setValues(data);
|
| 62 |
-
|
| 63 |
-
// 自動調整欄寬
|
| 64 |
-
sheet.autoResizeColumns(1, HEADERS.length);
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
// 設置最後更新時間(GMT+8)
|
| 68 |
-
const now = new Date();
|
| 69 |
-
const gmt8Time = new Date(now.getTime() + (8 * 60 * 60 * 1000));
|
| 70 |
-
sheet.getRange(1, HEADERS.length + 2).setValue('最後更新時間:');
|
| 71 |
-
sheet.getRange(1, HEADERS.length + 3).setValue(gmt8Time.toLocaleString('zh-TW', { timeZone: 'Asia/Taipei' }));
|
| 72 |
-
|
| 73 |
-
Logger.log('Spreadsheet updated successfully');
|
| 74 |
-
} catch (error) {
|
| 75 |
-
Logger.log('Error updating spreadsheet: ' + error.toString());
|
| 76 |
-
throw error; // 重新拋出錯誤以便在執行記錄中看到完整的錯誤信息
|
| 77 |
-
}
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
// 設置觸發器,每5分鐘執行一次
|
| 81 |
-
function createTrigger() {
|
| 82 |
-
// 刪除現有的觸發器
|
| 83 |
-
const triggers = ScriptApp.getProjectTriggers();
|
| 84 |
-
triggers.forEach(trigger => ScriptApp.deleteTrigger(trigger));
|
| 85 |
-
|
| 86 |
-
// 創建新的觸發器
|
| 87 |
-
ScriptApp.newTrigger('updateSpreadsheet')
|
| 88 |
-
.timeBased()
|
| 89 |
-
.everyMinutes(5)
|
| 90 |
-
.create();
|
| 91 |
-
|
| 92 |
-
Logger.log('Trigger created successfully');
|
| 93 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|