{"id":16105913,"url":"https://github.com/fightling/openweathermap","last_synced_at":"2025-03-18T08:31:57.705Z","repository":{"id":48075606,"uuid":"367923199","full_name":"fightling/openweathermap","owner":"fightling","description":"easy access current weather data from OpenWeatherMap","archived":false,"fork":false,"pushed_at":"2024-05-04T08:52:42.000Z","size":318,"stargazers_count":6,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T08:28:44.293Z","etag":null,"topics":["crates","openweathermap","openweathermap-api","rust","thread","weather-updates"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fightling.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-16T15:46:54.000Z","updated_at":"2024-08-14T12:20:45.000Z","dependencies_parsed_at":"2024-10-27T17:27:36.526Z","dependency_job_id":null,"html_url":"https://github.com/fightling/openweathermap","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fightling%2Fopenweathermap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fightling%2Fopenweathermap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fightling%2Fopenweathermap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fightling%2Fopenweathermap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fightling","download_url":"https://codeload.github.com/fightling/openweathermap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243910749,"owners_count":20367545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crates","openweathermap","openweathermap-api","rust","thread","weather-updates"],"created_at":"2024-10-09T19:11:11.393Z","updated_at":"2025-03-18T08:31:57.331Z","avatar_url":"https://github.com/fightling.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openweathermap [![Rust](https://github.com/fightling/openweathermap/actions/workflows/rust.yml/badge.svg)](https://github.com/fightling/openweathermap/actions/workflows/rust.yml)\n\n...is a *rust crate* which lets you easily access current weather data from [OpenWeatherMap](https://openweathermap.org/). This is an *unofficial* extension I have made to learn *rust* a little but I hope you have fun with it.\n\n## Contents\n\n\u003c!-- MDTOC maxdepth:6 firsth1:2 numbering:0 flatten:0 bullets:1 updateOnSave:1 --\u003e\n\n- [Contents](#contents)   \n- [How to use](#how-to-use)   \n   - [Get continuous weather updates](#get-continuous-weather-updates)   \n      - [First: Start polling](#first-start-polling)   \n      - [Then: Get weather updates](#then-get-weather-updates)   \n         - [Nothing New: `None`](#nothing-new-none)   \n         - [Weather Update: `CurrentWeather`](#weather-update-currentweather)   \n         - [Some Error: `Err`](#some-error-err)   \n   - [Get weather just once](#get-weather-just-once)   \n- [Reference Documentation](#reference-documentation)   \n- [Links](#links)   \n   - [Website](#website)   \n   - [*github* repository](#github-repository)   \n   - [on *crates.io*](#on-cratesio)   \n- [License](#license)   \n\n\u003c!-- /MDTOC --\u003e\n\n## How to use\n\nFirst add this crate to your dependencies in you `Cargo.toml` file:\n\n```toml\n[dependencies]\nopenweathermap = \"0.2.4\"\n```\n### Get continuous weather updates\n\nThen use the crate in your rust source file by calling `openweathermap::init()` which returns a receiver object.\nYou can then use this receiver object to call `openweathermap::update()` to get weather updates like in the following example:\n\n```rust\nextern crate openweathermap;\n\nuse openweathermap::{init,update};\n\nfn main() {\n    // start our observatory via OWM\n    let receiver = \u0026init(\"Berlin,DE\", \"metric\", \"en\", \"\u003cAPIKEY\u003e\", 10);\n    loop {\n        match update(receiver) {\n            Some(response) =\u003e match response {\n                Ok(current) =\u003e println!(\n                    \"Today's weather in {} is {}\",\n                    current.name.as_str(),\n                    current.weather[0].main.as_str()\n                ),\n                Err(e) =\u003e println!(\"Could not fetch weather because: {}\", e),\n            },\n            None =\u003e (),\n        }\n    }\n}\n```\n\n#### First: Start polling\n\n`init()` spawns a thread which then will periodically poll *OpenWeatherMap* for the latest current weather report.\nYou then can use `update()` to ask for it.\n\n#### Then: Get weather updates\n\nThere are three possible kinds of result you get from `update()` which you will have to face:\n\n##### Nothing New: `None`\n\n`update()` returns `None` if there is currently no new update available.\nWhich means: **You wont get any update twice!**\nIn other words: `update()` is not caching the last weather update for you.\n\n##### Weather Update: `CurrentWeather`\n\nIf a new update was downloaded by the polling thread `update()` returns some `CurrentWeather` object.\n`CurrentWeather` is a nested `struct` with the already parsed json properties.\nThose are well described [here](https://openweathermap.org/current#parameter).\n\n##### Some Error: `Err`\nOn error `update()` returns some `String` object which includes a brief error description.\n\nErrors may occur...\n- initially while **there is no update yet** you will get an `Err` which includes exactly the String `\"loading...\"` (predefined in `openweathermap::LOADING`).\n- if a **server error** response was received (e.g. `401 Unauthorized` if an **invalid API key** was used).\n- on **json errors** while parsing the response from *OpenWeatherMap*.\n\n### Get weather just once\n\nIf you need the weather just once you may use the method `weather()` which envelopes `init()` and `update()` into one single synchronous or asynchronous call.\nAfter the first successful weather update the spawned thread will stop immediately and you get the result in return.\n\n```rust\nextern crate openweathermap;\nuse openweathermap::blocking::weather;\n\nfn main() {\n    // start our observatory via OWM\n    match \u0026weather(\"Berlin,DE\", \"metric\", \"en\", \"\u003cAPIKEY\u003e\") {\n        Ok(current) =\u003e println!(\n            \"Today's weather in {} is {}\",\n            current.name.as_str(),\n            current.weather[0].main.as_str()\n        ),\n        Err(e) =\u003e println!(\"Could not fetch weather because: {}\", e),\n    }\n}\n\n```\n\nThere is a *blocking* and a *non-blocking* variant of `weather()`:\n\n- The above example uses the synchronous (*blocking*) variant `openweathermap::blocking::weather` which wont return until there is a new update.\n- If you like to deal with the returned *future* by yourself just use `openweathermap::weather` and asynchronously await the result until there is any.\n\n## Reference Documentation\n\nBeside this introduction there is a reference documentation which can be found [here](https://docs.rs/openweathermap).\n\n## Links\n\n### Website\n\nThis README tastes better at [openweathermap.thats-software.com](https://openweathermap.thats-software.com).\n\n### *github* repository\n\nFor the source code see [this repository](https://github.com/fightling/openweathermap) at *github.com*.\n\n### on *crates.io*\n\nPublished at [*crates.io*](https://crates.io/crates/openweathermap).\n\n## License\n\nopenweathermap is licensed under the *MIT license* (LICENSE-MIT or http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffightling%2Fopenweathermap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffightling%2Fopenweathermap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffightling%2Fopenweathermap/lists"}