Merge branch 'missing-dob' into 'main'
Add a command dumping missing date of births See merge request kernald/immich-tools!3
This commit is contained in:
commit
9f0a038cd9
7 changed files with 47 additions and 17 deletions
|
@ -39,6 +39,9 @@ pub(crate) enum PeopleCommands {
|
|||
#[arg(short, long)]
|
||||
vcard_file: PathBuf,
|
||||
},
|
||||
|
||||
/// Lists the people without date of birth
|
||||
MissingDateOfBirths {},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
|
|
19
src/commands/missing_date_of_birth.rs
Normal file
19
src/commands/missing_date_of_birth.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use crate::{utils::people::fetch_all_contacts, Client};
|
||||
use anyhow::Result;
|
||||
use log::*;
|
||||
|
||||
pub async fn missing_date_of_birth(client: &Client) -> Result<()> {
|
||||
let contacts = fetch_all_contacts(client).await?;
|
||||
let mut filtered_contacts = contacts
|
||||
.iter()
|
||||
.filter(|c| c.birth_date.is_none() && !c.name.is_empty())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
filtered_contacts.sort_by_key(|c| c.name.clone());
|
||||
|
||||
for c in filtered_contacts {
|
||||
info!("{}", c.name);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
pub mod missing_date_of_birth;
|
||||
pub mod server_version;
|
||||
pub mod sync_date_of_birth;
|
||||
|
|
|
@ -11,6 +11,7 @@ use vcard4::{
|
|||
|
||||
use crate::{
|
||||
types::{PersonResponseDto, PersonUpdateDto},
|
||||
utils::people::fetch_all_contacts,
|
||||
Client,
|
||||
};
|
||||
|
||||
|
@ -118,20 +119,3 @@ async fn update_person_bday(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn fetch_all_contacts(client: &Client) -> Result<Vec<PersonResponseDto>> {
|
||||
let mut all_people = Vec::new();
|
||||
let mut page_number = 1;
|
||||
let mut has_next_page = true;
|
||||
|
||||
while has_next_page {
|
||||
let fetched = client
|
||||
.get_all_people(Some(page_number.into()), None, Some(true))
|
||||
.await?;
|
||||
all_people.extend(fetched.people.clone());
|
||||
has_next_page = fetched.has_next_page.expect("Missing has_next_page");
|
||||
page_number += 1;
|
||||
}
|
||||
|
||||
Ok(all_people)
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@ use crate::args::Commands;
|
|||
use anyhow::Result;
|
||||
use args::{PeopleCommands, ServerCommands};
|
||||
use clap::Parser;
|
||||
use commands::missing_date_of_birth::missing_date_of_birth;
|
||||
use commands::server_version::server_version;
|
||||
use commands::sync_date_of_birth::sync_date_of_birth;
|
||||
use reqwest::header;
|
||||
|
||||
mod args;
|
||||
mod commands;
|
||||
mod utils;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
@ -21,6 +23,7 @@ async fn main() {
|
|||
|
||||
let res = match &args.command {
|
||||
Commands::People { people_command } => match people_command {
|
||||
PeopleCommands::MissingDateOfBirths {} => missing_date_of_birth(&client).await,
|
||||
PeopleCommands::SyncDateOfBirths { vcard_file } => {
|
||||
sync_date_of_birth(&client, vcard_file, args.dry_run).await
|
||||
}
|
||||
|
|
1
src/utils/mod.rs
Normal file
1
src/utils/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod people;
|
19
src/utils/people.rs
Normal file
19
src/utils/people.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use crate::{types::PersonResponseDto, Client};
|
||||
use anyhow::Result;
|
||||
|
||||
pub async fn fetch_all_contacts(client: &Client) -> Result<Vec<PersonResponseDto>> {
|
||||
let mut all_people = Vec::new();
|
||||
let mut page_number = 1;
|
||||
let mut has_next_page = true;
|
||||
|
||||
while has_next_page {
|
||||
let fetched = client
|
||||
.get_all_people(Some(page_number.into()), None, Some(true))
|
||||
.await?;
|
||||
all_people.extend(fetched.people.clone());
|
||||
has_next_page = fetched.has_next_page.expect("Missing has_next_page");
|
||||
page_number += 1;
|
||||
}
|
||||
|
||||
Ok(all_people)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue