Skip to content

Commit

Permalink
feat: refactoring + screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
RouHim committed Jun 16, 2022
1 parent 7b11c51 commit 14194f5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<i>Aggregate images taken this week, from previous years and presents them on a web page with slideshow.</i>
</p>

<p align="center">
<img src="https://raw.githubusercontent.com/RouHim/this-week-in-past/main/screenshot.jpg" width="500">
</p>

## Motivation

When I migrated my photo collection from google photos to a locally hosted instance of photoprism, I missed the
Expand All @@ -33,9 +37,6 @@ Example:

```bash
docker run -p 8080:8080 \
-e RESOURCE_PATHS=/resources \
-e CACHE_DIR=/cache \
-e WEATHER_ENABLED=false \
-v /path/to/pictures:/resources \
rouhim/this-week-in-past
```
Expand All @@ -48,8 +49,8 @@ All configuration is done via environment parameter:
|--------------------------|------------------------------------------------------------------------------------|---------------|
| RESOURCE_PATHS | Paths to the resources to load (comma separated) | |
| CACHE_DIR | Path to the caching to load, needs to read/write rights | |
| SLIDESHOW_INTERVAL | Interval of the slideshow in milliseconds | 10000 |
| WEATHER_ENABLED | Indicates if weather should be shown in the slideshow | true |
| 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 |
Expand Down
6 changes: 1 addition & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ services:
- twip-cache:/cache:rw # needs read/write
- ~/Downloads:/resources:ro # should be read only
ports:
- "8080:8080"
environment:
WEATHER_ENABLED: "false"
RESOURCE_PATHS: "/resources"
CACHE_DIR: "/cache"
- "8080:8080"
Binary file added screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/config_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ use actix_web::HttpResponse;
pub async fn get_slideshow_interval() -> HttpResponse {
HttpResponse::Ok()
.content_type("plain/text")
.body(env::var("SLIDESHOW_INTERVAL").unwrap_or_else(|_| "10000".to_string()))
.body(env::var("SLIDESHOW_INTERVAL").unwrap_or_else(|_| "30".to_string()))
}
9 changes: 9 additions & 0 deletions src/exif_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn get_exif_date(exif_data: &Exif) -> Option<NaiveDateTime> {
}

/// Reads the gps date from a given exif data entry
/// The gps date is used to determine the date the image was taken
fn get_gps_date(exif_data: &Exif) -> Option<NaiveDateTime> {
exif_data
.get_field(Tag::GPSDateStamp, In::PRIMARY)
Expand Down Expand Up @@ -62,6 +63,9 @@ pub fn load_exif(resource: &RemoteResource) -> Option<Exif> {
}

/// Augments the provided resource with meta information
/// The meta information is extracted from the exif data
/// If the exif data is not available, the meta information is extracted from the gps data
/// If the gps data is not available, the meta information is extracted from the file name
pub fn fill_exif_data(resource: &RemoteResource) -> RemoteResource {
let mut augmented_resource = resource.clone();

Expand Down Expand Up @@ -149,6 +153,9 @@ fn detect_orientation(exif_data: &Exif) -> Option<ImageOrientation> {
}
}

/// Detects the date from the file name
/// If the date is not found, the date is set to None
/// The chars '/', ' ', '.', '_' are replaced with '_'
fn detect_date_by_name(resource_path: &str) -> Option<NaiveDateTime> {
let parsed: Vec<NaiveDate> = resource_path
.replace('/', "_")
Expand All @@ -166,6 +173,8 @@ fn detect_date_by_name(resource_path: &str) -> Option<NaiveDateTime> {
}
}

/// Parses a string into a date
/// Returns None if the string could not be parsed
fn parse_from_str(shard: &str) -> Option<NaiveDate> {
// https://docs.rs/chrono/latest/chrono/format/strftime/index.html
let parse_results: Vec<NaiveDate> = vec![
Expand Down
2 changes: 1 addition & 1 deletion src/weather_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::weather_processor;

#[get("")]
pub async fn get_is_weather_enabled() -> HttpResponse {
let is_weather_enabled = env::var("WEATHER_ENABLED").unwrap_or_else(|_| "true".to_string());
let is_weather_enabled = env::var("WEATHER_ENABLED").unwrap_or_else(|_| "false".to_string());

HttpResponse::Ok()
.content_type("plain/text")
Expand Down
8 changes: 4 additions & 4 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ function slideshowTick() {
}
}

// Returns the slideshow interval
// Returns the slideshow interval in seconds
function getSlideshowInterval() {
let request = new XMLHttpRequest();
request.open('GET', `${window.location.href}api/config/interval`, false);
request.send(null);
if (request.status === 200) {
return request.responseText;
}
return 10000;
return 30;
}

// Starts the slideshow
Expand All @@ -132,10 +132,10 @@ function startSlideshow(response) {
slideshowTick();

// Load slideshow interval
let timeout = getSlideshowInterval();
let intervalInSeconds = getSlideshowInterval();

// Start image slideshow
setInterval(() => slideshowTick(), timeout);
setInterval(() => slideshowTick(), intervalInSeconds * 1000);
}

// Loads the available images from the server
Expand Down

0 comments on commit 14194f5

Please sign in to comment.