Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leo-210/sunny
An Open-meteo API client written in Gleam
https://github.com/leo-210/sunny
Last synced: about 1 month ago
JSON representation
An Open-meteo API client written in Gleam
- Host: GitHub
- URL: https://github.com/leo-210/sunny
- Owner: leo-210
- License: mit
- Created: 2024-08-03T15:04:18.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-08T13:46:22.000Z (5 months ago)
- Last Synced: 2024-10-30T16:58:38.194Z (2 months ago)
- Language: Gleam
- Size: 124 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🌤️ Sunny
An [Open-meteo API](https://open-meteo.com/) client written in Gleam.
Makes it easier to get weather forecasts, current and past weather data with different models anywhere you want !
[![Package Version](https://img.shields.io/hexpm/v/sunny)](https://hex.pm/packages/sunny)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/sunny/)## Installation
Add this package to your gleam project (not online yet)
```sh
gleam add sunny
```### Getting the current temperature in a city
Example code
Here, the function `send` corresponds to a function that makes a HTTP request.
For that, you can use HTTP clients such as `gleam_httpc` or `gleam_fetch`.```gleam
import gleam/dict
import gleam/io
import gleam/optionimport sunny
import sunny/api/forecast
import sunny/api/forecast/instant
import sunny/api/geocoding
import sunny/measurementpub fn main() {
let sunny = sunny.new()let assert Ok(location) =
sunny
|> geocoding.get_first_location(
geocoding.params("marseille")
|> geocoding.set_language(geocoding.French),
)
// Make a HTTP request
|> send
|> geocoding.get_first_resultlet assert Ok(forecast_result) =
sunny
|> forecast.get_forecast(
forecast.params(geocoding.location_to_position(location))
|> forecast.set_current([instant.Temperature2m]),
)
// Make a HTTP request
|> send
|> forecast.get_resultlet assert option.Some(current_data) = forecast_result.current
let assert Ok(temperature) =
current_data.data |> dict.get(instant.Temperature2m)io.println(
location.name
<> "'s current temperature is : "
<> measurement.to_string(temperature),
)
}
```More examples in the `test/examples` directory
Further documentation can be found at .
## Contributing
Contributions are very welcome ! Make a fork, and once you made the changes you wanted, make a PR.
### Todo
- Historical forecast API
- Air quality API