-
Notifications
You must be signed in to change notification settings - Fork 0
Add Shtab syncing support #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
замечания неприниципальные, но я смотрел только PR возможно имеет смысл посмотреть всю тулзу с т.зр. какой перестройки (типа чтение из хамстера один раз)
src/enrichment.rs
Outdated
let mut task_id: Option<String> = None; | ||
for extractor in extractors.into_iter() { | ||
task_id = extractor(link.url.as_str()); | ||
if task_id != None { | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut task_id: Option<String> = None; | |
for extractor in extractors.into_iter() { | |
task_id = extractor(link.url.as_str()); | |
if task_id != None { | |
break; | |
} | |
} | |
let task_id = extractors.into_iter().find_map(|extractor|extractor(link.url.as_str())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо, не знал про find_map()
!
src/enrichment.rs
Outdated
if links.is_empty() { | ||
None | ||
} else { | ||
let link = links[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if links.is_empty() { | |
None | |
} else { | |
let link = links[0]; | |
let link = links.get(0)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поправил, спасибо
run_mode: RunMode, | ||
) { | ||
let client = ShtabClient::new(Some(api_token)); | ||
let me = client.get_profile().await.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вместо unwrap яб возвращал anyhow::Result<()> и использовал ? - чуть сделает код короче
src/main.rs
Outdated
let activity_id:i64 = match activity_id { | ||
Some(activity_id) => activity_id, | ||
None => match std::env::var("HAMCLI_SHTAB_ACTIVITY") { | ||
Ok(activity_id_str) => activity_id_str.parse::<i64>().unwrap(), | ||
Err(_) => panic!( | ||
"Please specify activity id via --activity-id option or HAMCLI_SHTAB_ACTIVITY env var") | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let activity_id:i64 = match activity_id { | |
Some(activity_id) => activity_id, | |
None => match std::env::var("HAMCLI_SHTAB_ACTIVITY") { | |
Ok(activity_id_str) => activity_id_str.parse::<i64>().unwrap(), | |
Err(_) => panic!( | |
"Please specify activity id via --activity-id option or HAMCLI_SHTAB_ACTIVITY env var") | |
} | |
}; | |
let Some(activity_id:i64) = activity_id.or(std::env::var("HAMCLI_SHTAB_ACTIVITY")).and_then(|id| id.parse<i64>().ok()) else { | |
panic!( | |
"Please specify activity id via --activity-id option or HAMCLI_SHTAB_ACTIVITY env var") | |
}; |
код не проверял
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
О, спасибо, что заметил. Я здесь решил немного иначе сделать(см. 56954e2) - в cli::Commands
этот параметр не является опциональным (я делал немножко на будущее, но в итоге раздумал - когда прикручу функционал получения этого айдишника, тогда и сделаю опциональным).
let local_tz = Local::now().timezone(); | ||
|
||
let mut day = from; | ||
while day <= to { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
жалька что по ходу нельзя сделать
for day in (from..=to)
while day <= to { | ||
println!("Processing day {}", day); | ||
let next_day = day.checked_add_days(Days::new(1)).unwrap(); | ||
let tasks = get_tasks_with_durations(hamster_db.clone(), day, next_day, category.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а зачем каждый раз открывать файл? один раз в память считать и брать оттуда не проще?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Резонно. Подумаю над рефакторингом.
let task_id: i64 = match task_id { | ||
Some(task_id) => task_id.parse::<i64>().unwrap(), | ||
None => match run_mode { | ||
RunMode::DryRun => -1, | ||
RunMode::Normal => panic!( | ||
"Missing task id! ({}, '{}')", | ||
task_data.duration.as_hhmm(), | ||
task_data.title.unwrap_or("-".to_string()) | ||
), | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let task_id: i64 = match task_id { | |
Some(task_id) => task_id.parse::<i64>().unwrap(), | |
None => match run_mode { | |
RunMode::DryRun => -1, | |
RunMode::Normal => panic!( | |
"Missing task id! ({}, '{}')", | |
task_data.duration.as_hhmm(), | |
task_data.title.unwrap_or("-".to_string()) | |
), | |
}, | |
}; | |
let Some(task_id: i64) = task_id.map(|id|id.parse::<i64>().unwrap()).or( (run_mode==RunMode::DryRun).then_some(-1)) else { | |
panic!( | |
"Missing task id! ({}, '{}')", | |
task_data.duration.as_hhmm(), | |
task_data.title.unwrap_or("-".to_string()) | |
), | |
}; |
покороче, но не 100% понятней, конечно
src/main.rs
Outdated
); | ||
|
||
match &run_mode { | ||
RunMode::DryRun => println!("would add new record - {data_msg}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RunMode::DryRun => println!("would add new record - {data_msg}"), | |
RunMode::DryRun => println!("would add new record - {data_msg}"), |
или
RunMode::DryRun => println!("would add new record - {data_msg}"), | |
RunMode::DryRun => println!("would add new a record - {data_msg}"), |
src/main.rs
Outdated
); | ||
|
||
match &run_mode { | ||
RunMode::DryRun => println!("would add new record - {data_msg}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RunMode::DryRun => println!("would add new record - {data_msg}"), | |
RunMode::DryRun => println!("would add new record - {data_msg}"), |
или
RunMode::DryRun => println!("would add new record - {data_msg}"), | |
RunMode::DryRun => println!("would add new a record - {data_msg}"), |
Syncing with shtab.app