MCPcopy Index your code
hub / github.com/clearloop/leetcode-cli / get_question

Method get_question

src/cache/mod.rs:149–202  ·  view source on GitHub ↗
(&self, rfid: i32)

Source from the content-addressed store, hash-verified

147 /// Get question
148 #[allow(clippy::useless_let_if_seq)]
149 pub async fn get_question(&self, rfid: i32) -> Result<Question, Error> {
150 let target: Problem = problems.filter(fid.eq(rfid)).first(&mut self.conn()?)?;
151
152 let ids = match target.level {
153 1 => target.fid.to_string().green(),
154 2 => target.fid.to_string().yellow(),
155 3 => target.fid.to_string().red(),
156 _ => target.fid.to_string().dimmed(),
157 };
158
159 println!(
160 "\n[{}] {} {}\n\n",
161 &ids,
162 &target.name.bold().underline(),
163 "is on the run...".dimmed()
164 );
165
166 if target.category != "algorithms" {
167 return Err(anyhow!("No support for database and shell questions yet").into());
168 }
169
170 let mut rdesc = Question::default();
171 if !target.desc.is_empty() {
172 rdesc = serde_json::from_str(&target.desc)?;
173 } else {
174 let json: Value = self
175 .0
176 .clone()
177 .get_question_detail(&target.slug)
178 .await?
179 .json()
180 .await?;
181 debug!("{:#?}", &json);
182 match parser::desc(&mut rdesc, json) {
183 None => return Err(Error::NoneError),
184 Some(false) => {
185 return if self.is_session_bad().await {
186 Err(Error::CookieError)
187 } else {
188 Err(Error::PremiumError)
189 };
190 }
191 Some(true) => (),
192 }
193
194 // update the question
195 let sdesc = serde_json::to_string(&rdesc)?;
196 diesel::update(&target)
197 .set(desc.eq(sdesc))
198 .execute(&mut self.conn()?)?;
199 }
200
201 Ok(rdesc)
202 }
203
204 pub async fn get_tagged_questions(self, rslug: &str) -> Result<Vec<String>, Error> {
205 trace!("Geting {} questions...", &rslug);

Callers 3

pre_run_codeMethod · 0.80
runMethod · 0.80
runMethod · 0.80

Calls 4

descFunction · 0.85
connMethod · 0.80
get_question_detailMethod · 0.80
is_session_badMethod · 0.80

Tested by

no test coverage detected