Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,11 @@ urls = [
|
|
20 |
"https://www.booking.com/hotel/it/over-the-roof-top-roma.zh-tw.html",
|
21 |
"https://www.booking.com/hotel/it/rome-sweet-home-roma1234.zh-tw.html",
|
22 |
"https://www.booking.com/hotel/it/visione-guest-house-via-delle-fratte-36.zh-tw.html",
|
23 |
-
"https://www.booking.com/hotel/it/appartamento-roma-centro-roma5.zh-tw.html"
|
|
|
|
|
|
|
|
|
24 |
]
|
25 |
|
26 |
# 設定 User-Agent
|
@@ -55,10 +59,10 @@ else:
|
|
55 |
st.warning("無法從任何 URL 抓取數據。")
|
56 |
|
57 |
# Step 2: 上傳數據至 Google Sheets
|
58 |
-
def upload_to_google_sheet(df, spreadsheet_url,
|
59 |
try:
|
60 |
scope = ['https://www.googleapis.com/auth/spreadsheets']
|
61 |
-
creds = Credentials.
|
62 |
gs = gspread.authorize(creds)
|
63 |
sheet = gs.open_by_url(spreadsheet_url)
|
64 |
worksheet = sheet.get_worksheet(0)
|
@@ -75,7 +79,8 @@ creds_file = st.file_uploader("上傳 Google API 金鑰檔案", type=["json"])
|
|
75 |
# 上傳至 Google Sheets
|
76 |
if st.button("上傳數據至 Google Sheets") and data:
|
77 |
if creds_file is not None:
|
78 |
-
|
|
|
79 |
else:
|
80 |
st.error("請上傳 Google API 金鑰檔案")
|
81 |
|
|
|
20 |
"https://www.booking.com/hotel/it/over-the-roof-top-roma.zh-tw.html",
|
21 |
"https://www.booking.com/hotel/it/rome-sweet-home-roma1234.zh-tw.html",
|
22 |
"https://www.booking.com/hotel/it/visione-guest-house-via-delle-fratte-36.zh-tw.html",
|
23 |
+
"https://www.booking.com/hotel/it/appartamento-roma-centro-roma5.zh-tw.html",
|
24 |
+
"https://www.booking.com/hotel/us/loews-royal-pacific-resort-at-universal.zh-tw.html",
|
25 |
+
"https://www.booking.com/hotel/us/buena-vista-suites.zh-tw.html",
|
26 |
+
"https://www.booking.com/hotel/us/ramada-international-drive.zh-tw.html",
|
27 |
+
"https://www.booking.com/hotel/us/lake-buena-vista-14651-chelonia-parkway.zh-tw.html"
|
28 |
]
|
29 |
|
30 |
# 設定 User-Agent
|
|
|
59 |
st.warning("無法從任何 URL 抓取數據。")
|
60 |
|
61 |
# Step 2: 上傳數據至 Google Sheets
|
62 |
+
def upload_to_google_sheet(df, spreadsheet_url, creds_file_content):
|
63 |
try:
|
64 |
scope = ['https://www.googleapis.com/auth/spreadsheets']
|
65 |
+
creds = Credentials.from_service_account_info(creds_file_content, scopes=scope)
|
66 |
gs = gspread.authorize(creds)
|
67 |
sheet = gs.open_by_url(spreadsheet_url)
|
68 |
worksheet = sheet.get_worksheet(0)
|
|
|
79 |
# 上傳至 Google Sheets
|
80 |
if st.button("上傳數據至 Google Sheets") and data:
|
81 |
if creds_file is not None:
|
82 |
+
creds_content = creds_file.read() # 讀取上傳的文件內容
|
83 |
+
upload_to_google_sheet(df, spreadsheet_url, creds_content)
|
84 |
else:
|
85 |
st.error("請上傳 Google API 金鑰檔案")
|
86 |
|