Skip to main content

get_attendance/
get_attendance.rs

1//! Download all attendance records from the device.
2//!
3//! Run with: `cargo run --example get_attendance -- 192.168.1.201 [port]`
4
5use std::time::Duration;
6use zkteco::Zk;
7
8fn main() -> zkteco::ZkResult<()> {
9    let mut args = std::env::args().skip(1);
10    let ip = args.next().expect("usage: get_attendance <ip> [port]");
11    let port: u16 = args.next().and_then(|p| p.parse().ok()).unwrap_or(4370);
12
13    let mut zk = Zk::builder(ip)
14        .port(port)
15        .timeout(Duration::from_secs(15))
16        .omit_ping(true)
17        .build();
18
19    zk.connect()?;
20    zk.disable_device()?;
21    let logs = zk.get_attendance()?;
22    zk.enable_device()?;
23    zk.disconnect()?;
24
25    println!("{} records", logs.len());
26    for a in logs {
27        println!(
28            "  {} user={} status={} {}",
29            a.timestamp,
30            a.user_id,
31            a.status,
32            a.punch_label()
33        );
34    }
35    Ok(())
36}