PART 6

行事曆與天氣查詢

行程管理與外部 API 整合

自然語言新增行程 OpenWeatherMap API 即時天氣資訊

📅 行事曆管理

智慧行程新增

使用自然語言輸入:

  • 行程:明天下午3點開會
  • 行程:週六早上10點健身房
  • 行程:下週三晚上7點聚餐

AI 解析結果

{
    "date": "2026-01-16",
    "time": "15:00",
    "event": "開會",
    "location": "",
    "category": "工作"
}
行事曆清單

🏷️ 行程類別

💼

工作

會議、專案

👨‍👩‍👧‍👦

家庭

家人聚會

🎉

社交

朋友聚會

🏥

健康

健檢、看醫生

📚

學習

課程、講座

✈️

旅遊

出遊規劃

🌤️ 天氣查詢功能

OpenWeatherMap API 整合

def get_weather_from_openweathermap(city, api_key):
    url = f"https://api.openweathermap.org/data/2.5/weather"
    url += f"?q={city}&appid={api_key}&units=metric&lang=zh_tw"

    response = requests.get(url)
    data = response.json()

    return {
        'weather': data['weather'][0]['description'],
        'temp': data['main']['temp'],
        'humidity': data['main']['humidity']
    }
API 特色:支援繁體中文天氣描述、攝氏溫度、多城市查詢!

🌡️ 天氣資訊呈現

🌤️ 台北市 即時天氣

☀️

天氣狀況:晴朗

🌡️ 溫度:25°C | 體感:27°C

💧 濕度:65% | 💨 風速:3.5 m/s

容錯機制:OpenWeatherMap 失敗時,自動降級使用 AI 查詢天氣資訊。

📌 Part 6 小結

核心功能

  • 智慧行程解析:AI 自動解析日期、時間、事件
  • 多類別管理:工作/家庭/社交/學習等分類
  • 天氣 API 整合:OpenWeatherMap 即時天氣
  • 多城市支援:台灣主要城市天氣查詢
  • 容錯降級:API 失敗時使用 AI 備援
前往 Part 7:新聞、電影與股票分析 →