Skip to content

Commit

Permalink
feat: offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
barakplasma committed Jan 14, 2024
1 parent 5c7d9b2 commit 36d78ab
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 18 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"] }
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ims_structs::LocationForecasts, serde_xml_rs::Error> {
pub fn get_israeli_weather_forecast(offline: bool) -> Result<ims_structs::LocationForecasts, serde_xml_rs::Error> {
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");

Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 36d78ab

Please sign in to comment.