Skip to content

A lightweight IRC bot that provides real-time weather information using the Open-Meteo API. WeatherBot is designed to be simple to set up, easy to configure, and free to use as it relies on the free Open-Meteo API service.

License

Notifications You must be signed in to change notification settings

MansionNET/WeatherBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

MansionNet Weather Bot

A lightweight, reliable IRC bot that provides real-time weather information using the Open-Meteo API. Designed for 24/7 operation with robust error handling and efficient resource usage.

Features

  • Real-time weather data from Open-Meteo API (no API key required)
  • Global city search with geocoding
  • Colorized IRC output with weather icons
  • SSL/TLS support for secure connections
  • Automatic reconnection with exponential backoff
  • Efficient resource usage with proper timeout handling
  • Production-tested for 24/7 stability

Weather Information Provided

  • Current temperature (°C)
  • Weather conditions (clear, cloudy, rain, snow, thunderstorm, etc.)
  • Relative humidity (%)
  • Wind speed (km/h)

Commands

  • !weather <city> - Get current weather for any city worldwide
    • Example: !weather Belgrade
    • Example: !weather New York
  • !help - Display bot help information

Requirements

  • Python 3.7+
  • requests library

Installation

  1. Clone the repository:
git clone https://github.com/MansionNET/weatherbot.git
cd weatherbot
  1. Install dependencies:
pip install requests
  1. Configure the bot: Edit weatherbot.py and update:
self.server = "your.irc.server.com"
self.port = 6697  # or 6667 for non-SSL
self.nickname = "WeatherBot"
self.channels = ["#channel1", "#channel2"]
  1. (Optional) For NickServ authentication, add:
self.password = "your_nickserv_password"

And uncomment the NickServ identification lines in the connect() method.

Running the Bot

Manual Start

python3 weatherbot.py

As a systemd Service (Linux)

  1. Create service file /etc/systemd/system/weatherbot.service:
[Unit]
Description=MansionNet Weather Bot
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=youruser
WorkingDirectory=/path/to/weatherbot
ExecStart=/usr/bin/python3 /path/to/weatherbot/weatherbot.py
Restart=always
RestartSec=30

[Install]
WantedBy=multi-user.target
  1. Enable and start:
sudo systemctl enable weatherbot.service
sudo systemctl start weatherbot.service
  1. Check status:
sudo systemctl status weatherbot.service

Configuration Options

SSL/TLS

The bot uses SSL by default. To disable certificate verification (for self-signed certs):

self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE

Connection Timeouts

  • Socket timeout: 1.0 second (prevents blocking)
  • API request timeout: 5 seconds (for geocoding and weather data)
  • Reconnection delay: 30 seconds (after errors)

Customization

  • Colors: Modify the TEXT variable in get_weather() for different IRC color codes
  • Weather Icons: Customize the symbols (▸, ❋, ⟳) in the return string
  • Channels: Add or remove channels in the self.channels list

API Information

This bot uses the free Open-Meteo API:

  • No API key required
  • No rate limiting for reasonable use
  • Global coverage
  • Real-time data updates

Geocoding provided by Open-Meteo's geocoding API.

Architecture

Connection Management

  • Non-blocking socket operations with timeout
  • Automatic reconnection on connection loss
  • Proper handling of IRC PING/PONG
  • Buffer management for split messages

Error Handling

  • Graceful handling of network timeouts
  • Unicode decode error recovery
  • API request failure fallbacks
  • Connection closed detection

Resource Efficiency

  • Sleep intervals during idle periods (0.1s when no data)
  • Socket timeouts prevent CPU spinning
  • Efficient buffer processing
  • Minimal memory footprint

Troubleshooting

Bot not connecting

  • Check IRC server address and port
  • Verify SSL/TLS requirements
  • Check firewall rules for outbound connections

Bot joins but doesn't respond

  • Verify the bot is in the correct channels
  • Check channel permissions (some channels may be +m or require voice)
  • Review logs for error messages

High CPU usage

  • Ensure you're running the latest version with timeout fixes
  • Check network stability
  • Monitor system logs for connection issues

Weather data not updating

  • Verify internet connectivity
  • Check if Open-Meteo API is accessible
  • Ensure DNS resolution is working

Production Deployment

Security Considerations

  • Store NickServ passwords in environment variables or secrets management
  • Use SSL/TLS for IRC connections when available
  • Run the bot as a non-privileged user
  • Monitor logs for unusual activity

Monitoring

  • Use systemd status to check bot health
  • Monitor CPU and memory usage
  • Set up log rotation for long-term operation
  • Consider external monitoring for uptime

Example Usage

<user> !weather London
<WeatherBot> London, United Kingdom 【Partly cloudy】 ▸ 12°C ❋ 78% ⟳ 15 km/h

<user> !weather Tokyo
<WeatherBot> Tokyo, Japan 【Clear sky】 ▸ 18°C ❋ 45% ⟳ 8 km/h

<user> !weather Belgrade
<WeatherBot> Belgrade, Serbia 【Overcast】 ▸ 5°C ❋ 82% ⟳ 12 km/h

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Development Guidelines

  • Follow PEP 8 style guidelines
  • Add comments for complex logic
  • Test thoroughly before submitting PRs
  • Update README for new features

License

[Your chosen license - e.g., MIT, GPL, etc.]

Acknowledgments

  • Weather data provided by Open-Meteo
  • Built for the MansionNET IRC community
  • Inspired by classic IRC bots and modern Python practices

Changelog

v2.0 (2026-01-26)

  • Fixed: Critical CPU spinning bug in main message loop
  • Added: Socket timeout handling for non-blocking operations
  • Added: API request timeouts (5 seconds)
  • Improved: Connection error handling and reconnection logic
  • Improved: Resource efficiency and stability for 24/7 operation

v1.0 (Initial Release)

  • Basic weather information functionality
  • Multi-channel support
  • IRC color formatting
  • Open-Meteo API integration

Support

For issues, questions, or suggestions:


Made with ☕ for the MansionNET community

About

A lightweight IRC bot that provides real-time weather information using the Open-Meteo API. WeatherBot is designed to be simple to set up, easy to configure, and free to use as it relies on the free Open-Meteo API service.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages