From 36d78ab1b5c77124c504cb5ec7753384e76945a2 Mon Sep 17 00:00:00 2001 From: Michael Salaverry Date: Sun, 14 Jan 2024 15:15:50 +0000 Subject: [PATCH] feat: offline mode --- .github/workflows/release.yml | 2 +- Cargo.lock | 30 ++++++++++++++++++------------ Cargo.toml | 6 +++--- src/lib.rs | 3 ++- src/main.rs | 6 +++++- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e7eec21..cb801e7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,7 @@ jobs: - name: Build run: cargo build --release - name: Check semver - - uses: obi1kenobi/cargo-semver-checks-action@v2 + uses: obi1kenobi/cargo-semver-checks-action@v2 - run: shx cp ./target/release/weather ./target/release/weather_${{matrix.os}} if: runner.os == 'Linux' || runner.os == 'macOS' - run: shx cp target/release/weather.exe target/release/weather_windows-latest.exe diff --git a/Cargo.lock b/Cargo.lock index 1b0d3d3..10148aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,6 +53,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + [[package]] name = "block-buffer" version = "0.10.3" @@ -169,7 +175,7 @@ version = "4.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" dependencies = [ - "bitflags", + "bitflags 1.3.2", "clap_derive", "clap_lex", "is-terminal", @@ -897,11 +903,11 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.55" +version = "0.10.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" +checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" dependencies = [ - "bitflags", + "bitflags 2.4.1", "cfg-if", "foreign-types", "libc", @@ -929,18 +935,18 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "111.25.0+1.1.1t" +version = "300.2.1+3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3173cd3626c43e3854b1b727422a276e568d9ec5fe8cec197822cf52cfb743d6" +checksum = "3fe476c29791a5ca0d1273c697e96085bbabbbea2ef7afd5617e78a4b40332d3" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.90" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" +checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" dependencies = [ "cc", "libc", @@ -1086,7 +1092,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1156,7 +1162,7 @@ version = "0.36.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", @@ -1191,7 +1197,7 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -1642,7 +1648,7 @@ checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "weather" -version = "0.2.3" +version = "0.3.0" dependencies = [ "cached-path", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 5b63b83..5e5d930 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "weather" -version = "0.2.3" +version = "0.3.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,7 +14,7 @@ serde-xml-rs = "0.6" serde_json = "1" [target.'cfg(target_arch = "aarch64")'.dependencies] -openssl = { version = "0.10.55", features = ["vendored"] } +openssl = { version = "0.10.62", features = ["vendored"] } [target.'cfg(target_arch = "arm")'.dependencies] -openssl = { version = "0.10.55", features = ["vendored"] } +openssl = { version = "0.10.62", features = ["vendored"] } diff --git a/src/lib.rs b/src/lib.rs index 5d97fb9..df8222a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,11 +7,12 @@ mod ims_structs; static WEATHER_URL: &str = "https://ims.gov.il/sites/default/files/ims_data/xml_files/isr_cities_1week_6hr_forecast.xml"; -pub fn get_israeli_weather_forecast() -> Result { +pub fn get_israeli_weather_forecast(offline: bool) -> Result { let cache = Cache::builder() .dir(std::env::temp_dir().join("weather/")) .connect_timeout(std::time::Duration::from_secs(60)) .timeout(std::time::Duration::from_secs(60)) + .offline(offline) .build() .expect("unable to start download cache"); diff --git a/src/main.rs b/src/main.rs index 922e2b8..a968c1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,12 +19,16 @@ struct Args { /// Ignore location and print all weather data #[arg(short, long, default_value_t = false)] all: bool, + + /// Offline mode + #[arg(short, long, default_value_t = false)] + offline: bool, } fn main() { let args = Args::parse(); - let forecasts = get_israeli_weather_forecast().expect("failed to get forecast"); + let forecasts = get_israeli_weather_forecast(args.offline).expect("failed to get forecast"); let now = chrono::Utc::now();