Skip to content

jingchenyc/weather_assitant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Weather Assistant - Project of ccClub

A Python-based Line Bot that provides real-time weather updates and clothing recommendations by fetching data from the Central Weather Bureau API. Deployed using Google Cloud Functions for automated and scheduled execution.

Table of Contents

Introduction

Weather Assistant is a collaborative project aimed at creating a Line Bot that provides users with weather forecasts, rain probability, and clothing suggestions based on the latest meteorological data. The bot fetches data from the Central Weather Bureau's API and is deployed using Google Cloud Functions.

Screenshot 2024-10-01 at 12 09 51 PM

Features

  • Real-Time Weather Data: Fetches current weather observations and 36-hour forecasts.
  • Rain Gear Suggestions: Advises users on whether to carry rain gear based on rain probability.
  • Clothing Recommendations: Provides clothing suggestions based on temperature and comfort index.
  • Chinese Character Recognition: Recognizes both traditional and simplified Chinese characters.
  • Automated Execution: Deployed on Google Cloud Functions for scheduled tasks.
  • Line Bot Integration: Users can interact with the bot through the Line messaging app.

Project Structure

  • linebot_main.py: The main script for the Line Bot webhook.
  • linebot_get_weather.py: Contains functions to fetch and process weather data.
  • linebot_requirements.txt: Lists all the dependencies required for the project.

Prerequisites

  • Python 3.9 or above
  • Line Developer Account
  • Google Cloud Platform Account
  • Libraries listed in requirements.txt
  • Access to the Central Weather Bureau API

Installation

  1. Clone the Repository

    git clone https://github.com/jingchenyc/weather-assistant.git
  2. Navigate to the Project Directory

    cd linebot_weather-assistant
  3. Install Required Libraries

    pip install -r linebot_requirements.txt

Usage

Setting Up the Line Bot

  1. Create a Line Channel

  2. Enable Webhook

    • Set up your webhook URL in the Line Developer Console.
    • Use Google Cloud Functions URL as your webhook endpoint.

Deploying to Google Cloud Functions

  1. Create a New Cloud Function

  2. Configure the Function

    • Environment: 2nd Generation
    • Runtime: Python 3.9
    • Entry Point: Specify the function name in linebot_main.py.
    • Authentication: Allow unauthenticated invocations.
  3. Upload Code

    • Upload linebot_main.py, linebot_get_weather.py, and linebot_requirements.txt.
  4. Set Environment Variables

    • Add your Line Bot credentials (CHANNEL_SECRET, CHANNEL_ACCESS_TOKEN).

Setting Up API Access

How to Run

  1. Local Testing

    • Install dependencies:
      pip install -r linebot_requirements.txt
    • Run the bot locally:
      python linebot_main.py
    • Use a tool like ngrok to expose your local server for webhook testing.
  2. Deploying to Cloud Functions

    • Use the gcloud CLI for deployment:
      gcloud functions deploy weather-assistant \
        --runtime python39 \
        --trigger-http \
        --allow-unauthenticated \
        --entry-point YOUR_ENTRY_POINT \
        --source .
      Replace YOUR_ENTRY_POINT with the actual function name.
  3. Interacting with the Bot

    • Add the Line Bot to your Line app using the provided QR code.
    • Send messages to receive weather updates and recommendations.

Debugging Notes

  • Data Structure Differences

    • Noticed differences in data structures between versions by Danny and Wei.
    • The order of weatherElement's elementName varies, affecting data extraction.
    • Ensure consistent data processing by checking the API response structure.
  • Line Bot Message Handling

Contributing

We welcome contributions from the community. Feel free to open issues or submit pull requests.

Acknowledgments

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Project of Python Programming ccClub (founded by NTU CSIE alumni)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages