From c574b871941452296651fde3115b27c0d4b73744 Mon Sep 17 00:00:00 2001 From: tripercy Date: Thu, 22 Aug 2024 11:40:46 +0700 Subject: [PATCH 1/2] fix: daily problem parsing Changed a key to fix parsing daily problem request. Fixed when id for daily problem should be fetched. Before, it will always be fetched for the `pick` option regardless of the existence of the `-d` option --- Cargo.lock | 2 +- src/cache/parser.rs | 2 +- src/cmds/pick.rs | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3e5cc1..15bde1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1327,7 +1327,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "leetcode-cli" -version = "0.4.3" +version = "0.4.4" dependencies = [ "anyhow", "async-trait", diff --git a/src/cache/parser.rs b/src/cache/parser.rs index 0474c1f..329455d 100644 --- a/src/cache/parser.rs +++ b/src/cache/parser.rs @@ -98,7 +98,7 @@ pub fn tags(v: Value) -> Option> { pub fn daily(v: Value) -> Option { trace!("Parse daily..."); let v_obj = v.as_object()?.get("data")?.as_object()?; - match v_obj.get("dailyQuestionRecord") { + match v_obj.get("activeDailyCodingChallengeQuestion") { // Handle on leetcode-com Some(v) => v, // Handle on leetcode-cn diff --git a/src/cmds/pick.rs b/src/cmds/pick.rs index 3597d5d..ca36826 100644 --- a/src/cmds/pick.rs +++ b/src/cmds/pick.rs @@ -130,7 +130,12 @@ impl Command for PickCommand { crate::helper::filter(&mut problems, query.to_string()); } - let daily_id = if m.contains_id("daily") { + let daily = match m.get_one::("daily") { + Some(x) => x, + None => &false, + }; + + let daily_id = if *daily { Some(cache.get_daily_problem_id().await?) } else { None From 0b331f78be5eaae0056472336882a5c44f4ad099 Mon Sep 17 00:00:00 2001 From: tripercy Date: Fri, 23 Aug 2024 10:05:26 +0700 Subject: [PATCH 2/2] fix: comment problem desc Changed desc comment to render Question.content instead of Question.t_content, which was empty. --- src/cache/models.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache/models.rs b/src/cache/models.rs index 30a7691..2f49eaf 100644 --- a/src/cache/models.rs +++ b/src/cache/models.rs @@ -151,7 +151,7 @@ impl Question { } pub fn desc_comment(&self, conf: &Config) -> String { - let desc = self.t_content.render(); + let desc = self.content.render(); let mut res = desc.lines().fold("\n".to_string(), |acc, e| { acc + "" + conf.code.comment_leading.as_str() + " " + e + "\n"