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.
- Introduction
- Features
- Project Structure
- Prerequisites
- Installation
- Usage
- How to Run
- Debugging Notes
- Contributing
- Acknowledgments
- License
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.
- 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.
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.
- Python 3.9 or above
- Line Developer Account
- Google Cloud Platform Account
- Libraries listed in
requirements.txt - Access to the Central Weather Bureau API
-
Clone the Repository
git clone https://github.com/jingchenyc/weather-assistant.git
-
Navigate to the Project Directory
cd linebot_weather-assistant -
Install Required Libraries
pip install -r linebot_requirements.txt
-
Create a Line Channel
- Follow the instructions on Oxxo Studio's Line Developer Tutorial.
- Obtain your
Channel SecretandChannel Access Token.
-
Enable Webhook
- Set up your webhook URL in the Line Developer Console.
- Use Google Cloud Functions URL as your webhook endpoint.
-
Create a New Cloud Function
- Go to the Google Cloud Console.
- Click on "Create Function".
-
Configure the Function
- Environment: 2nd Generation
- Runtime: Python 3.9
- Entry Point: Specify the function name in
linebot_main.py. - Authentication: Allow unauthenticated invocations.
-
Upload Code
- Upload
linebot_main.py,linebot_get_weather.py, andlinebot_requirements.txt.
- Upload
-
Set Environment Variables
- Add your Line Bot credentials (
CHANNEL_SECRET,CHANNEL_ACCESS_TOKEN).
- Add your Line Bot credentials (
- Register for access to the Central Weather Bureau API.
- Update the API endpoints in
get_weather.pyas needed.
-
Local Testing
- Install dependencies:
pip install -r linebot_requirements.txt
- Run the bot locally:
python linebot_main.py
- Use a tool like
ngrokto expose your local server for webhook testing.
- Install dependencies:
-
Deploying to Cloud Functions
- Use the
gcloudCLI for deployment:Replacegcloud functions deploy weather-assistant \ --runtime python39 \ --trigger-http \ --allow-unauthenticated \ --entry-point YOUR_ENTRY_POINT \ --source .YOUR_ENTRY_POINTwith the actual function name.
- Use the
-
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.
-
Data Structure Differences
- Noticed differences in data structures between versions by Danny and Wei.
- The order of
weatherElement'selementNamevaries, affecting data extraction. - Ensure consistent data processing by checking the API response structure.
-
Line Bot Message Handling
- For replying to address messages, refer to Oxxo Studio's Line Reply Message Tutorial.
We welcome contributions from the community. Feel free to open issues or submit pull requests.
- Team Members: Danny, Wei, and Ruth for their significant contributions.
- Assistants: Special thanks to the teaching assistant for guidance on using Cloud Functions and Line Bot integration.
- References:
This project is licensed under the MIT License. See the LICENSE file for details.