Skip to content

Commit

Permalink
configurable number of import days
Browse files Browse the repository at this point in the history
  • Loading branch information
ducc committed Feb 7, 2024
1 parent 2108077 commit b8212df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ pub enum Measure {
Ml,
UsFl,
L,
Cl,
}

impl<'de> Deserialize<'de> for Measure {
Expand All @@ -472,6 +473,7 @@ impl<'de> Deserialize<'de> for Measure {
"ml" => Measure::Ml,
"us fl" | "usfl" => Measure::UsFl,
"l" => Measure::L,
"cl" => Measure::Cl,
_ => return Err(D::Error::custom(format!("unhandled variant: {}", s2))),
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

tracing_subscriber::fmt::init();

let import_days = std::env::var("NUTRACHECK_IMPORT_DAYS")?.parse::<i64>()?;

let mongo_client = mongo::Client::new_from_env().await?;

let nc_client = nutracheck::Client::new_from_env().await?;

let todays_date = Utc::now().date_naive();

for date in dateiter::DateRange(todays_date - Duration::weeks(52), todays_date) {
for date in dateiter::DateRange(todays_date - Duration::days(import_days), todays_date) {
let entries = nc_client.entries(date).await.expect("getting entries");

mongo_client.insert_entries(date, entries).await?;
Expand Down

0 comments on commit b8212df

Please sign in to comment.