Make ECUS importer work

korrat
Aug 8, 2023, 7:46 PM
ETFHPNXRUPMQ3NLA3O4RN6HNRGU3VGPGS3LLUWWJ7UGH6RTQK75AC

Dependencies

  • [2] PUJBHX7C Add importer for ECUS transactions

Change contents

  • edit in importers/ecus/src/lib.rs at line 21
    [2.691]
    [2.691]
    use time::Date;
  • replacement in importers/ecus/src/lib.rs at line 66
    [2.1797][2.1797:1813]()
    todo!()
    [2.1797]
    [2.1813]
    Ok(self.config.base_account.clone())
    }
    fn date(&self, file: &Utf8Path) -> Option<Result<Date, Self::Error>> {
    let ecus_transactions = {
    std::fs::read_to_string(file)
    .into_diagnostic()
    .and_then(|data| {
    serde_json::from_str::<Vec<EcusTransaction>>(&data).into_diagnostic()
    })
    };
    let ecus_transactions = match ecus_transactions {
    Ok(data) => data,
    Err(error) => return Some(Err(error)),
    };
    ecus_transactions
    .into_iter()
    .map(|EcusTransaction { date, .. }| date.date())
    .max()
    .map(Ok)
  • edit in importers/ecus/src/lib.rs at line 159
    [2.4511]
    [2.4511]
    }
    fn filename(&self, _file: &Utf8Path) -> Option<Result<String, Self::Error>> {
    Some(Ok(String::from("ecus-transactions.json")))
  • replacement in importers/ecus/src/lib.rs at line 165
    [2.4518][2.4518:4608]()
    fn identify(&self, _file: &Utf8Path) -> Result<bool, Self::Error> {
    Ok(false)
    [2.4518]
    [2.4608]
    fn identify(&self, file: &Utf8Path) -> Result<bool, Self::Error> {
    let data = std::fs::read_to_string(file).into_diagnostic()?;
    match serde_json::from_str::<Vec<EcusTransaction>>(&data) {
    Ok(_) => Ok(true),
    Err(error) => {
    tracing::debug!(?error, %file, data, "ignoring file due to deserialization error");
    Ok(false)
    }
    }