Add a command dumping missing date of births

This commit is contained in:
Marc Plano-Lesay 2024-10-28 15:27:35 +11:00
parent bc09979a62
commit dfac23a225
7 changed files with 47 additions and 17 deletions

View 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(())
}

View file

@ -1,2 +1,3 @@
pub mod missing_date_of_birth;
pub mod server_version;
pub mod sync_date_of_birth;

View file

@ -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)
}