Add a command dumping missing date of births
This commit is contained in:
parent
bc09979a62
commit
dfac23a225
7 changed files with 47 additions and 17 deletions
|
@ -39,6 +39,9 @@ pub(crate) enum PeopleCommands {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
vcard_file: PathBuf,
|
vcard_file: PathBuf,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Lists the people without date of birth
|
||||||
|
MissingDateOfBirths {},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[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 server_version;
|
||||||
pub mod sync_date_of_birth;
|
pub mod sync_date_of_birth;
|
||||||
|
|
|
@ -11,6 +11,7 @@ use vcard4::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
types::{PersonResponseDto, PersonUpdateDto},
|
types::{PersonResponseDto, PersonUpdateDto},
|
||||||
|
utils::people::fetch_all_contacts,
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,20 +119,3 @@ async fn update_person_bday(
|
||||||
|
|
||||||
Ok(())
|
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 anyhow::Result;
|
||||||
use args::{PeopleCommands, ServerCommands};
|
use args::{PeopleCommands, ServerCommands};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use commands::missing_date_of_birth::missing_date_of_birth;
|
||||||
use commands::server_version::server_version;
|
use commands::server_version::server_version;
|
||||||
use commands::sync_date_of_birth::sync_date_of_birth;
|
use commands::sync_date_of_birth::sync_date_of_birth;
|
||||||
use reqwest::header;
|
use reqwest::header;
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
mod commands;
|
mod commands;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -21,6 +23,7 @@ async fn main() {
|
||||||
|
|
||||||
let res = match &args.command {
|
let res = match &args.command {
|
||||||
Commands::People { people_command } => match people_command {
|
Commands::People { people_command } => match people_command {
|
||||||
|
PeopleCommands::MissingDateOfBirths {} => missing_date_of_birth(&client).await,
|
||||||
PeopleCommands::SyncDateOfBirths { vcard_file } => {
|
PeopleCommands::SyncDateOfBirths { vcard_file } => {
|
||||||
sync_date_of_birth(&client, vcard_file, args.dry_run).await
|
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