Skip to content

Commit cb950f1

Browse files
committed
feat: open-meteo datasource
1 parent 21a4762 commit cb950f1

File tree

9 files changed

+1484
-0
lines changed

9 files changed

+1484
-0
lines changed

cmd/renderers_imports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
_ "github.com/rubiojr/ergs/pkg/datasources/github/renderer"
2121
_ "github.com/rubiojr/ergs/pkg/datasources/hackernews/renderer"
2222
_ "github.com/rubiojr/ergs/pkg/datasources/homeassistant/renderer"
23+
_ "github.com/rubiojr/ergs/pkg/datasources/openmeteo/renderer"
2324
_ "github.com/rubiojr/ergs/pkg/datasources/rss/renderer"
2425
_ "github.com/rubiojr/ergs/pkg/datasources/rtve/renderer"
2526
_ "github.com/rubiojr/ergs/pkg/datasources/timestamp/renderer"

datasources.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
_ "github.com/rubiojr/ergs/pkg/datasources/github"
1111
_ "github.com/rubiojr/ergs/pkg/datasources/hackernews"
1212
_ "github.com/rubiojr/ergs/pkg/datasources/homeassistant"
13+
_ "github.com/rubiojr/ergs/pkg/datasources/openmeteo"
1314
_ "github.com/rubiojr/ergs/pkg/datasources/rss"
1415
_ "github.com/rubiojr/ergs/pkg/datasources/rtve"
1516
_ "github.com/rubiojr/ergs/pkg/datasources/timestamp"

docs/datasources/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ This directory contains documentation for individual datasources available in Er
1818
### Home & Utilities
1919
- **[Home Assistant](homeassistant.md)** - Capture Home Assistant events (state changes, service calls, automations) via the WebSocket API
2020
- **[Datadis](datadis.md)** - Fetch electricity consumption data from Datadis (Spanish electricity data platform)
21+
- **[Gas Stations](gasstations.md)** - Fetch current fuel prices from Spanish gas stations
22+
23+
### Weather
24+
- **[Open-Meteo](openmeteo.md)** - Fetch current weather data for any location worldwide (free, no API key required)
25+
26+
### News & Content
27+
- **[Hacker News](hackernews.md)** - Fetch stories, comments, and other items from Hacker News
28+
- **[RSS](rss.md)** - Fetch articles from RSS/Atom feeds
29+
- **[RTVE](rtve.md)** - Fetch episodes from RTVE (Spanish TV) shows
2130

2231

2332
## General Usage

docs/datasources/openmeteo.md

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
# Open-Meteo Weather Datasource
2+
3+
The Open-Meteo datasource fetches current weather data for any location worldwide using the free Open-Meteo API. It automatically geocodes location names and provides comprehensive weather information including temperature, wind, humidity, pressure, and UV index.
4+
5+
## Features
6+
7+
- 🌍 **Worldwide Coverage** - Fetch weather for any location globally
8+
- 📍 **Automatic Geocoding** - Simply provide a location name (city, town, etc.)
9+
- 🌡️ **Comprehensive Data** - Temperature, feels-like, wind, humidity, pressure, UV index
10+
- 🎨 **Weather Icons** - Visual representation with emoji icons for each weather condition
11+
- 🆓 **Free API** - No API key required, uses the free Open-Meteo service
12+
- 🔄 **Real-time Updates** - Configurable fetch intervals for up-to-date weather
13+
14+
## Configuration
15+
16+
### Basic Configuration
17+
18+
```toml
19+
[datasources.madrid_weather]
20+
type = 'openmeteo'
21+
interval = '1h0m0s' # Check weather every hour
22+
[datasources.madrid_weather.config]
23+
location = 'Madrid' # Location name to geocode
24+
```
25+
26+
### Example: Multiple Locations
27+
28+
```toml
29+
[datasources.london_weather]
30+
type = 'openmeteo'
31+
interval = '30m0s'
32+
[datasources.london_weather.config]
33+
location = 'London'
34+
35+
[datasources.tokyo_weather]
36+
type = 'openmeteo'
37+
interval = '1h0m0s'
38+
[datasources.tokyo_weather.config]
39+
location = 'Tokyo'
40+
41+
[datasources.newyork_weather]
42+
type = 'openmeteo'
43+
interval = '1h0m0s'
44+
[datasources.newyork_weather.config]
45+
location = 'New York'
46+
```
47+
48+
### Configuration Options
49+
50+
| Field | Type | Required | Default | Description |
51+
|-------|------|----------|---------|-------------|
52+
| `location` | string | Yes | - | Location name to fetch weather for (e.g., "Madrid", "San Francisco") |
53+
54+
### Validation Rules
55+
56+
- Location must be a non-empty string
57+
- The location will be automatically geocoded using Open-Meteo's geocoding API
58+
- If multiple matches are found, the first (most relevant) result is used
59+
60+
## Data Schema
61+
62+
The datasource stores the following fields for each weather report:
63+
64+
| Field | Type | Description |
65+
|-------|------|-------------|
66+
| `location` | TEXT | City/location name |
67+
| `country` | TEXT | Country name |
68+
| `latitude` | REAL | Location latitude |
69+
| `longitude` | REAL | Location longitude |
70+
| `timezone` | TEXT | Timezone identifier (e.g., "Europe/Madrid") |
71+
| `population` | INTEGER | Population of the location (if available) |
72+
| `temperature` | REAL | Current temperature (°C) |
73+
| `wind_speed` | REAL | Wind speed (km/h) |
74+
| `wind_direction` | REAL | Wind direction (degrees) |
75+
| `weather_code` | INTEGER | WMO weather code (0-99) |
76+
| `weather_description` | TEXT | Human-readable weather condition |
77+
| `humidity` | REAL | Relative humidity (%) |
78+
| `apparent_temperature` | REAL | Feels-like temperature (°C) |
79+
| `surface_pressure` | REAL | Surface pressure (hPa) |
80+
| `sealevel_pressure` | REAL | Sea level pressure (hPa) |
81+
| `uv_index` | REAL | Maximum UV index for the day |
82+
83+
## Weather Codes and Icons
84+
85+
The datasource uses WMO weather codes and displays them with appropriate icons:
86+
87+
| Code | Condition | Icon |
88+
|------|-----------|------|
89+
| 0 | Clear Sky | ☀️ |
90+
| 1 | Mainly Clear | 🌤️ |
91+
| 2 | Partly Cloudy ||
92+
| 3 | Overcast | ☁️ |
93+
| 45, 48 | Fog | 🌫️ |
94+
| 51-57 | Drizzle | 🌧️ |
95+
| 61-67 | Rain | 🌧️ |
96+
| 71-77 | Snow | ❄️ |
97+
| 80-82 | Rain Showers | 🌦️ |
98+
| 85-86 | Snow Showers | 🌨️ |
99+
| 95-99 | Thunderstorm | ⛈️ |
100+
101+
## Usage Examples
102+
103+
### Fetching Data
104+
105+
```bash
106+
# One-time fetch
107+
./ergs fetch --config config.toml
108+
109+
# Stream results to see them in real-time
110+
./ergs fetch --stream --config config.toml
111+
```
112+
113+
### Searching Weather Data
114+
115+
```bash
116+
# Search for a specific location
117+
./ergs search --query "Madrid" --datasource madrid_weather
118+
119+
# Search for weather conditions
120+
./ergs search --query "rain" --datasource madrid_weather
121+
122+
# Search by temperature
123+
./ergs search --query "temperature" --datasource madrid_weather
124+
125+
# Search across all weather datasources
126+
./ergs search --query "sunny"
127+
```
128+
129+
### Running the Scheduler
130+
131+
```bash
132+
# Start the daemon to fetch weather data at configured intervals
133+
./ergs serve --config config.toml
134+
```
135+
136+
## Sample Output
137+
138+
When fetching or streaming data, you'll see output like this:
139+
140+
```
141+
🌤️ Madrid, Spain
142+
🌡️ Temperature: 22.5°C (feels like 21.8°C)
143+
💨 Wind: 12.3 km/h at 180°
144+
☁️ Condition: Partly Cloudy
145+
💧 Humidity: 65.2%
146+
🔆 UV Index: 6
147+
📊 Pressure: 1013.2 hPa (surface), 1013.5 hPa (sea level)
148+
📍 Coordinates: 40.4168, -3.7038
149+
🕒 Timezone: Europe/Madrid
150+
📅 2024-01-15 10:30:00
151+
Metadata:
152+
location: Madrid
153+
country: Spain
154+
latitude: 40.4168
155+
longitude: -3.7038
156+
timezone: Europe/Madrid
157+
temperature: 22.5
158+
wind_speed: 12.3
159+
weather_description: Partly Cloudy
160+
humidity: 65.2
161+
uv_index: 6
162+
```
163+
164+
## Data Source
165+
166+
This datasource uses the free [Open-Meteo API](https://open-meteo.com/):
167+
168+
- **Geocoding**: `geocoding-api.open-meteo.com` - Converts location names to coordinates
169+
- **Weather Data**: `api.open-meteo.com` - Provides current weather and forecasts
170+
- **Air Quality**: `air-quality-api.open-meteo.com` - UV index and air quality data
171+
- **No API Key Required**: Free for non-commercial use
172+
- **Attribution**: Data provided by Open-Meteo.com
173+
174+
## Location Examples
175+
176+
You can use various location formats:
177+
178+
```toml
179+
# City names
180+
location = 'Tokyo'
181+
location = 'Paris'
182+
location = 'New York'
183+
184+
# City with state/region
185+
location = 'San Francisco, California'
186+
location = 'Cambridge, Massachusetts'
187+
188+
# Smaller towns
189+
location = 'El Masnou'
190+
location = 'Zermatt'
191+
192+
# International locations
193+
location = 'São Paulo'
194+
location = 'München'
195+
location = 'København'
196+
```
197+
198+
## Performance Considerations
199+
200+
- **API Rate Limits**: Open-Meteo is free but has reasonable rate limits
201+
- **Update Frequency**: Weather data typically updates every 15-60 minutes
202+
- **Recommended Interval**: 30 minutes to 1 hour is usually sufficient
203+
- **Storage**: Creates one block per fetch, deduplicates based on weather conditions
204+
- **Network**: Requires 3 API calls per fetch (geocoding, weather, air quality)
205+
206+
## Troubleshooting
207+
208+
### Common Issues
209+
210+
1. **Location not found**: Check spelling and try adding country name
211+
```toml
212+
location = 'Springfield, USA' # More specific
213+
```
214+
215+
2. **API timeout errors**: Check internet connection or increase timeout
216+
- Default timeout is 30 seconds
217+
- API may be temporarily unavailable
218+
219+
3. **No weather data**: Verify location is valid by testing in browser:
220+
```
221+
https://geocoding-api.open-meteo.com/v1/search?name=YourLocation
222+
```
223+
224+
### Debug Tips
225+
226+
```bash
227+
# Test with a well-known location first
228+
location = 'London'
229+
230+
# Check logs for geocoding results
231+
./ergs serve --config config.toml --verbose
232+
233+
# Verify API accessibility
234+
curl "https://api.open-meteo.com/v1/forecast?latitude=51.5074&longitude=-0.1278&current=temperature_2m"
235+
```
236+
237+
## Integration with Ergs
238+
239+
The Open-Meteo datasource integrates seamlessly with Ergs' features:
240+
241+
- **Scheduling**: Configure different update intervals per location
242+
- **Search**: Full-text search across location, conditions, and weather data
243+
- **Storage**: Automatic deduplication prevents storing duplicate weather reports
244+
- **Streaming**: Real-time weather updates during fetch operations
245+
- **Web Interface**: Beautiful visual rendering with weather icons and gradients
246+
247+
## Privacy and Terms
248+
249+
- **No Personal Data**: Only location names are sent to Open-Meteo API
250+
- **No API Key**: No authentication required
251+
- **Terms of Use**: Follow Open-Meteo's [terms of service](https://open-meteo.com/en/terms)
252+
- **Attribution**: Credit Open-Meteo when sharing weather data publicly
253+
254+
## Advanced Usage
255+
256+
### Combining with Other Datasources
257+
258+
Track weather alongside your other data:
259+
260+
```toml
261+
# Weather for your location
262+
[datasources.local_weather]
263+
type = 'openmeteo'
264+
interval = '30m0s'
265+
[datasources.local_weather.config]
266+
location = 'Your City'
267+
268+
# Track when weather changes affect your activities
269+
[datasources.github]
270+
type = 'github'
271+
interval = '30m0s'
272+
[datasources.github.config]
273+
token = 'your-token'
274+
```
275+
276+
### Multiple Locations Monitoring
277+
278+
Monitor weather in different cities:
279+
280+
```toml
281+
[datasources.home_weather]
282+
type = 'openmeteo'
283+
interval = '30m0s'
284+
[datasources.home_weather.config]
285+
location = 'San Francisco'
286+
287+
[datasources.office_weather]
288+
type = 'openmeteo'
289+
interval = '30m0s'
290+
[datasources.office_weather.config]
291+
location = 'London'
292+
293+
[datasources.vacation_weather]
294+
type = 'openmeteo'
295+
interval = '1h0m0s'
296+
[datasources.vacation_weather.config]
297+
location = 'Barcelona'
298+
```
299+
300+
This makes it easy to track weather patterns across multiple locations and correlate with your other activities and data sources.

pkg/config/config.toml.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ api_key = ''
7676
# longitude = 2.3199 # Required: Your longitude
7777
# radius = 10000 # Required: Search radius in meters
7878

79+
# # Open-Meteo Weather - Fetch current weather data for a location
80+
# [datasources.weather]
81+
# type = 'openmeteo'
82+
# # interval = '1h0m0s' # Check weather every hour
83+
# [datasources.weather.config]
84+
# location = 'Madrid' # Required: Location name (city, town, etc.) - will be geocoded automatically
85+
7986
# # Home Assistant - Capture events via WebSocket API
8087
# [datasources.home]
8188
# type = 'homeassistant'

0 commit comments

Comments
 (0)