https://github.com/mansionnet/weatherbot
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.
https://github.com/mansionnet/weatherbot
irc irc-bot metheorology open-meteo python weather weather-api weather-bot
Last synced: 5 days ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/mansionnet/weatherbot
- Owner: MansionNET
- License: mit
- Created: 2025-01-01T19:16:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-25T00:32:20.000Z (about 1 year ago)
- Last Synced: 2025-07-03T08:08:06.006Z (7 months ago)
- Topics: irc, irc-bot, metheorology, open-meteo, python, weather, weather-api, weather-bot
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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 ` - 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:
```bash
git clone https://github.com/MansionNET/weatherbot.git
cd weatherbot
```
2. Install dependencies:
```bash
pip install requests
```
3. Configure the bot:
Edit `weatherbot.py` and update:
```python
self.server = "your.irc.server.com"
self.port = 6697 # or 6667 for non-SSL
self.nickname = "WeatherBot"
self.channels = ["#channel1", "#channel2"]
```
4. (Optional) For NickServ authentication, add:
```python
self.password = "your_nickserv_password"
```
And uncomment the NickServ identification lines in the `connect()` method.
## Running the Bot
### Manual Start
```bash
python3 weatherbot.py
```
### As a systemd Service (Linux)
1. Create service file `/etc/systemd/system/weatherbot.service`:
```ini
[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
```
2. Enable and start:
```bash
sudo systemctl enable weatherbot.service
sudo systemctl start weatherbot.service
```
3. Check status:
```bash
sudo systemctl status weatherbot.service
```
## Configuration Options
### SSL/TLS
The bot uses SSL by default. To disable certificate verification (for self-signed certs):
```python
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](https://open-meteo.com/):
- 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
```
!weather London
London, United Kingdom 【Partly cloudy】 ▸ 12°C ❋ 78% ⟳ 15 km/h
!weather Tokyo
Tokyo, Japan 【Clear sky】 ▸ 18°C ❋ 45% ⟳ 8 km/h
!weather Belgrade
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](https://open-meteo.com/)
- 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:
- Open an issue on GitHub
- Contact on IRC: #lobby on irc.inthemansion.com port: 6697 or https://webirc.inthemansion.com/
---
Made with ☕ for the MansionNET community