Spaces:
Sleeping
Sleeping
Update weather_service.py
Browse files- weather_service.py +5 -2
weather_service.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
| 1 |
# weather_service.py
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
-
# 中央氣象署 (CWA) 開放資料平台的授權碼是公開的,可以直接使用
|
| 5 |
-
CWA_AUTH_KEY = "CWA-15722330-8255-4252-9523-28E03C5C764C"
|
| 6 |
CWA_WEATHER_API = "https://opendata.cwa.gov.tw/api/v1/rest/datastore/O-A0003-001"
|
| 7 |
|
| 8 |
def fetch_weather_by_location(location_name: str) -> str:
|
| 9 |
"""根據地點名稱查詢即時天氣資訊。"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
params = {
|
| 11 |
"Authorization": CWA_AUTH_KEY,
|
| 12 |
"format": "JSON",
|
|
|
|
| 1 |
# weather_service.py
|
| 2 |
import requests
|
| 3 |
+
from config import CWA_AUTH_KEY # [修改] 從 config 匯入金鑰
|
| 4 |
|
|
|
|
|
|
|
| 5 |
CWA_WEATHER_API = "https://opendata.cwa.gov.tw/api/v1/rest/datastore/O-A0003-001"
|
| 6 |
|
| 7 |
def fetch_weather_by_location(location_name: str) -> str:
|
| 8 |
"""根據地點名稱查詢即時天氣資訊。"""
|
| 9 |
+
# [新增] 檢查金鑰是否存在
|
| 10 |
+
if not CWA_AUTH_KEY:
|
| 11 |
+
return "❌ 天氣查詢失敗:管理者尚未設定 CWA_AUTH_KEY。"
|
| 12 |
+
|
| 13 |
params = {
|
| 14 |
"Authorization": CWA_AUTH_KEY,
|
| 15 |
"format": "JSON",
|