Skip to content
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

chore(dep): bump the deps group with 9 updates #157

Merged
merged 5 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 151 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ path = "src/bin/lc.rs"

[package]
name = "leetcode-cli"
version = "0.4.3"
version = "0.4.4"
authors = ["clearloop <tianyi.gc@gmail.com>"]
edition = "2021"
description = "Leetcode command-line interface in rust."
Expand All @@ -18,30 +18,30 @@ readme = './README.md'
[dependencies]
async-trait = "0.1.80"
tokio = { version = "1.38.0", features = ["full"] }
clap = { version = "4.5.4", features = ["cargo"] }
clap = { version = "4.5.8", features = ["cargo"] }
colored = "2.1.0"
dirs = "5.0.1"
env_logger = "0.11.3"
keyring = "2.3.3"
log = "0.4.21"
log = "0.4.22"
openssl = "0.10.64"
pyo3 = { version = "0.21.2", optional = true }
pyo3 = { version = "0.22.0", optional = true }
rand = "0.8.5"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
toml = "0.8.13"
regex = "1.10.4"
serde_json = "1.0.120"
toml = "0.8.14"
regex = "1.10.5"
scraper = "0.19.0"
anyhow = "1.0.86"
clap_complete = "4.5.2"
clap_complete = "4.5.7"
thiserror = "1.0.61"

[dependencies.diesel]
version = "2.2.0"
version = "2.2.1"
features = ["sqlite"]

[dependencies.reqwest]
version = "0.12.4"
version = "0.12.5"
features = ["gzip", "json"]

[features]
Expand Down
7 changes: 2 additions & 5 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ pub fn conn(p: String) -> SqliteConnection {

/// Condition submit or test
#[derive(Clone, Debug)]
#[derive(Default)]
pub enum Run {
Test,
#[default]
Submit,
}

impl Default for Run {
fn default() -> Self {
Run::Submit
}
}

/// Requests if data not download
#[derive(Clone)]
Expand Down
6 changes: 3 additions & 3 deletions src/cache/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ pub fn problem(problems: &mut Vec<Problem>, v: Value) -> Option<()> {
// Handle on leetcode-com
Some(s) => s as i32,
// Handle on leetcode-cn
None => fid_obj.as_str()?.split(" ").last()?.parse::<i32>().ok()?,
None => fid_obj.as_str()?.split(' ').last()?.parse::<i32>().ok()?,
};

problems.push(Problem {
category: v.get("category_slug")?.as_str()?.to_string(),
fid: fid,
fid,
id: stat.get("question_id")?.as_i64()? as i32,
level: p.get("difficulty")?.as_object()?.get("level")?.as_i64()? as i32,
locked: p.get("paid_only")?.as_bool()?,
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn daily(v: Value) -> Option<i32> {
// Handle on leetcode-com
Some(v) => v,
// Handle on leetcode-cn
None => v_obj.get("todayRecord")?.as_array()?.get(0)?,
None => v_obj.get("todayRecord")?.as_array()?.first()?,
}
.as_object()?
.get("question")?
Expand Down
1 change: 0 additions & 1 deletion src/cmds/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ impl Command for ListCommand {
.get_many::<i32>("range")
.ok_or(Error::NoneError)?
.copied()
.into_iter()
.collect();
ps.retain(|x| num_range[0] <= x.fid && x.fid <= num_range[1]);
}
Expand Down
13 changes: 5 additions & 8 deletions src/cmds/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,8 @@ impl Command for PickCommand {
let fid = match m.contains_id("name") {
// check for name specified, or closest name
true => {
match m.get_one::<String>("name").map(|name| name) {
Some(quesname) => match closest_named_problem(&problems, quesname) {
Some(p) => p,
None => 1,
},
match m.get_one::<String>("name") {
Some(quesname) => closest_named_problem(&problems, quesname).unwrap_or(1),
None => {
// Pick random without specify id
let problem = &problems[rand::thread_rng().gen_range(0..problems.len())];
Expand Down Expand Up @@ -190,7 +187,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i
let mut table: Vec<usize> = vec![0; (max_name_size + 1) * (lookup_name.len() + 1)];

// this is guaranteed because of the earlier max None propegation
assert!(problems.len() > 0);
assert!(!problems.is_empty());
let mut max_score = 0;
let mut current_problem = &problems[0];
for problem in problems {
Expand All @@ -204,7 +201,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i

if this_score > max_score {
max_score = this_score;
current_problem = &problem;
current_problem = problem;
}
}

Expand All @@ -213,7 +210,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i

// Longest commong subsequence DP approach O(nm) space and time. Table must be at least
// (text1.len() + 1) * (text2.len() + 1) length or greater and is mutated every call
fn longest_common_subsequence(table: &mut Vec<usize>, text1: &str, text2: &str) -> usize {
fn longest_common_subsequence(table: &mut [usize], text1: &str, text2: &str) -> usize {
assert!(table.len() >= (text1.len() + 1) * (text2.len() + 1));
let height: usize = text1.len() + 1;
let width: usize = text2.len() + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Command for StatCommand {
);

// lines
for (i, l) in vec![(easy, easy_ac), (medium, medium_ac), (hard, hard_ac)]
for (i, l) in [(easy, easy_ac), (medium, medium_ac), (hard, hard_ac)]
.iter()
.enumerate()
{
Expand Down
30 changes: 19 additions & 11 deletions src/config/cookies.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Cookies in config
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use std::{
fmt::{self, Display},
str::FromStr,
};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum LeetcodeSite {
Expand All @@ -22,12 +24,14 @@ impl FromStr for LeetcodeSite {
}
}

impl ToString for LeetcodeSite {
fn to_string(&self) -> String {
match self {
LeetcodeSite::LeetcodeCom => "leetcode.com".to_string(),
LeetcodeSite::LeetcodeCn => "leetcode.cn".to_string(),
}
impl Display for LeetcodeSite {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
LeetcodeSite::LeetcodeCom => "leetcode.com",
LeetcodeSite::LeetcodeCn => "leetcode.cn",
};

write!(f, "{s}")
}
}

Expand All @@ -49,8 +53,12 @@ impl Default for Cookies {
}
}

impl std::string::ToString for Cookies {
fn to_string(&self) -> String {
format!("LEETCODE_SESSION={};csrftoken={};", self.session, self.csrf)
impl Display for Cookies {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"LEETCODE_SESSION={};csrftoken={};",
self.session, self.csrf
)
}
}
2 changes: 1 addition & 1 deletion src/config/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Storage {
self.scripts = Some("scripts".into());
}

let p = PathBuf::from(root).join(&self.scripts.ok_or(Error::NoneError)?);
let p = PathBuf::from(root).join(self.scripts.ok_or(Error::NoneError)?);
if !PathBuf::from(&p).exists() {
std::fs::create_dir(&p)?
}
Expand Down
3 changes: 2 additions & 1 deletion src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ mod filter {
ids.iter().for_each(|x| {
map.insert(x.to_string(), true).unwrap_or_default();
});
ps.retain(|x| map.get(&x.id.to_string()).is_some());

ps.retain(|x| map.contains_key(&x.id.to_string()));
Ok(())
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/plugins/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::anyhow;
use diesel::prelude::*;
use keyring::Entry;
use openssl::{hash, pkcs5, symm};
use std::collections::HashMap;
use std::{collections::HashMap, fmt::Display};

/// LeetCode Cookies Schema
mod schema {
Expand Down Expand Up @@ -34,9 +34,13 @@ pub struct Ident {
session: String,
}

impl std::string::ToString for Ident {
fn to_string(&self) -> String {
format!("LEETCODE_SESSION={};csrftoken={};", self.session, self.csrf)
impl Display for Ident {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"LEETCODE_SESSION={};csrftoken={};",
self.session, self.csrf
)
}
}

Expand Down Expand Up @@ -64,7 +68,7 @@ pub fn cookies() -> Result<Ident> {
debug!("Chrome Cookies path is {:?}", &p);
let mut conn = cache::conn(p.to_string_lossy().to_string());
let res = cookies
.filter(host_key.like(format!("#{}", ccfg.site.to_string())))
.filter(host_key.like(format!("#{}", ccfg.site)))
.load::<Cookies>(&mut conn)
.expect("Loading cookies from google chrome failed.");

Expand Down
26 changes: 9 additions & 17 deletions src/plugins/leetcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ impl LeetCode {
json.insert("variables", r#"{"slug": "$slug"}"#.replace("$slug", slug));
json.insert(
"query",
vec![
"query getTopicTag($slug: String!) {",
["query getTopicTag($slug: String!) {",
" topicTag(slug: $slug) {",
" questions {",
" questionId",
" }",
" }",
"}",
]
"}"]
.join("\n"),
);

Expand Down Expand Up @@ -151,31 +149,27 @@ impl LeetCode {
json.insert("operationName", "daily".to_string());
json.insert(
"query",
vec![
"query daily {",
["query daily {",
" activeDailyCodingChallengeQuestion {",
" question {",
" questionFrontendId",
" }",
" }",
"}",
]
"}"]
.join("\n"),
);
}
config::LeetcodeSite::LeetcodeCn => {
json.insert("operationName", "questionOfToday".to_string());
json.insert(
"query",
vec![
"query questionOfToday {",
["query questionOfToday {",
" todayRecord {",
" question {",
" questionFrontendId",
" }",
" }",
"}",
]
"}"]
.join("\n"),
);
}
Expand All @@ -201,8 +195,7 @@ impl LeetCode {
let mut json: Json = HashMap::new();
json.insert(
"query",
vec![
"query getQuestionDetail($titleSlug: String!) {",
["query getQuestionDetail($titleSlug: String!) {",
" question(titleSlug: $titleSlug) {",
" content",
" stats",
Expand All @@ -213,8 +206,7 @@ impl LeetCode {
" metaData",
" translatedContent",
" }",
"}",
]
"}"]
.join("\n"),
);

Expand All @@ -232,7 +224,7 @@ impl LeetCode {
json: Some(json),
mode: Mode::Post,
name: "get_problem_detail",
url: self.conf.sys.urls.graphql.into(),
url: self.conf.sys.urls.graphql,
}
.send(&self.client)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/pym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn exec(module: &str) -> Result<Vec<String>> {

// pygil
Python::with_gil(|py| {
let pym = PyModule::from_code(py, &script, "plan.py", "plan")?;
let pym = PyModule::from_code_bound(py, &script, "plan.py", "plan")?;
pym.getattr("plan")?.call1((sps, stags))?.extract()
})
.map_err(Into::into)
Expand Down
Loading