Skip to content

Commit

Permalink
feat: add more configuration options, add dependency check
Browse files Browse the repository at this point in the history
  • Loading branch information
RouHim committed Jun 17, 2022
1 parent 79832d1 commit 0578b9e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 19 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,30 @@ jobs:
- name: Test code
run: cargo test

check-dependencies:
name: Check for unmet dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- uses: Swatinem/rust-cache@v1 # use /rust/cargo caching

- name: Install cargo-udeps
run: cargo install cargo-udeps --locked

- name: Analyze dependencies
run: cargo +nightly udeps

build:
name: Build container image
needs: [ check-config, check-repo, check-code-style, check-code, test ]
needs: [ check-config, check-repo, check-code-style, check-code, test, check-dependencies ]
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: 1 # use the new docker build backend
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rand = "0.8.5"
log = "0.4.17"
mime_guess = "2.0.4"
openssl = { version = "0.10.40", features = ["vendored"] }
raytracer = "0.2.2"

[dev-dependencies]
assertor = "0.0.1"
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ docker run -p 8080:8080 \

All configuration is done via environment variables:

| Name | Description | Default value |
|--------------------------|------------------------------------------------------------------------------------------------|---------------|
| RESOURCE_PATHS | Paths to the resources to load (comma separated), must not be set when using container. | |
| CACHE_DIR | Path to the caching to load, needs to read/write rights, must not be set when using container. | |
| SLIDESHOW_INTERVAL | Interval of the slideshow in seconds | 30 |
| WEATHER_ENABLED | Indicates if weather should be shown in the slideshow | false |
| BIGDATA_CLOUD_API_KEY | To resolve geo coordinates to city name. Obtain here: https://www.bigdatacloud.com | |
| OPEN_WEATHER_MAP_API_KEY | To receive weather live data. Obtain here: https://openweathermap.org/api | |
| LOCATION_NAME | Weather location | Berlin |
| LANGUAGE | Weather language | en |
| HOME_ASSISTANT_BASE_URL | Home assistant base url | |
| HOME_ASSISTANT_ENTITY_ID | Home assistant entity id to load the weather from | |
| HOME_ASSISTANT_API_TOKEN | Home assistant api access token | |
| Name | Description | Default value |
|--------------------------|-------------------------------------------------------------------------------------------------------|---------------|
| RESOURCE_PATHS | Paths to the resources to load (comma separated), must not be set when using container. | |
| CACHE_DIR | Path to the caching to load, needs to read/write rights, must not be set when using container. | |
| SLIDESHOW_INTERVAL | Interval of the slideshow in seconds | 30 |
| DATE_FORMAT | Date format of the image taken date (https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html) | %d.%m.%Y |
| BIGDATA_CLOUD_API_KEY | To resolve geo coordinates to city name. Obtain here: https://www.bigdatacloud.com | |
| OPEN_WEATHER_MAP_API_KEY | To receive weather live data. Obtain here: https://openweathermap.org/api | |
| WEATHER_ENABLED | Indicates if weather should be shown in the slideshow | false |
| WEATHER_LOCATION | Weather location | Berlin |
| WEATHER_LANGUAGE | Weather language | en |
| WEATHER_UNIT | Weather units (metric or imperial) | metric |
| HOME_ASSISTANT_BASE_URL | Home assistant base url | |
| HOME_ASSISTANT_ENTITY_ID | Home assistant entity id to load the weather from | |
| HOME_ASSISTANT_API_TOKEN | Home assistant api access token | |
12 changes: 10 additions & 2 deletions src/resource_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ pub async fn build_display_value(

// Append taken date
if let Some(taken_date) = resource.taken {
display_value.push_str(taken_date.date().format("%d.%m.%Y").to_string().as_str());
}
let date_format: String =
env::var("DATE_FORMAT").unwrap_or_else(|_| "%d.%m.%Y".to_string());
display_value.push_str(
taken_date
.date()
.format(date_format.as_str())
.to_string()
.as_str(),
);
};

// Append city name
let city_name = get_city_name(resource, geo_location_cache_mutex.clone()).await;
Expand Down
6 changes: 3 additions & 3 deletions src/weather_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pub async fn get_current_weather() -> Option<String> {
}

let api_key: String = env::var("OPEN_WEATHER_MAP_API_KEY").unwrap();
let city: String = env::var("LOCATION_NAME").unwrap_or_else(|_| "Berlin".to_string());
let units: String = env::var("UNITS").unwrap_or_else(|_| "metric".to_string());
let language: String = env::var("LANGUAGE").unwrap_or_else(|_| "en".to_string());
let city: String = env::var("WEATHER_LOCATION").unwrap_or_else(|_| "Berlin".to_string());
let units: String = env::var("WEATHER_UNIT").unwrap_or_else(|_| "metric".to_string());
let language: String = env::var("WEATHER_LANGUAGE").unwrap_or_else(|_| "en".to_string());

let response = reqwest::get(format!(
"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units={units}&lang={language}"
Expand Down

0 comments on commit 0578b9e

Please sign in to comment.