rustfm_scraper/app/
stats.rs

1use anyhow::Result;
2
3use crate::config::Config;
4use crate::{app, files};
5
6pub fn stats(s: app::Stats, config: Config) -> Result<()> {
7    let username = match s.username {
8        Some(username) => username,
9        None => config.default_username,
10    };
11
12    match files::find_which_file_exists(&username)? {
13        Some(_) => true,
14        None => {
15            println!(
16                "No file for `{}` exists. Stats cannot be calculated.",
17                &username
18            );
19            return Ok(());
20        }
21    };
22
23    let saved_scrobbles = files::load_from_any_file(&username)?;
24
25    println!("Crunching stats for {}...\n", &username);
26    let stats = saved_scrobbles.generate_stats();
27    stats.print();
28
29    Ok(())
30}