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
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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue