Skip to content

Commit 986ac95

Browse files
committed
Use frontend question id in favor of question id
1 parent 6a45502 commit 986ac95

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ fn main() {
4949
.next();
5050
if code.is_none() {
5151
println!("Problem {} has no rust version.", &id);
52-
solved_ids.push(id);
52+
solved_ids.push(problem.question_id);
5353
continue;
5454
}
5555
let code = code.unwrap();
5656

57-
let file_name = format!("n{:04}_{}", id, problem.title_slug.replace("-", "_"));
57+
let file_name = format!("n{:04}_{}", problem.question_id, problem.title_slug.replace("-", "_"));
5858
let file_path = Path::new("./src").join(format!("{}.rs", file_name));
5959
if file_path.exists() {
6060
panic!("problem already initialized");
@@ -65,7 +65,7 @@ fn main() {
6565
.replace("__PROBLEM_TITLE__", &problem.title)
6666
.replace("__PROBLEM_DESC__", &build_desc(&problem.content))
6767
.replace("__PROBLEM_DEFAULT_CODE__", &code.default_code)
68-
.replace("__PROBLEM_ID__", &format!("{}", id))
68+
.replace("__PROBLEM_ID__", &format!("{}", problem.question_id))
6969
.replace("__EXTRA_USE__", &parse_extra_use(&code.default_code));
7070

7171
let mut file = fs::OpenOptions::new()

src/problem.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ query questionData($titleSlug: String!) {
1717
}"#;
1818
const QUESTION_QUERY_OPERATION: &str = "questionData";
1919

20-
pub fn get_problem(id: u32) -> Option<Problem> {
20+
pub fn get_problem(frontend_question_id: u32) -> Option<Problem> {
2121
let problems = get_problems().unwrap();
2222
for problem in problems.stat_status_pairs.iter() {
23-
if problem.stat.question_id == id {
23+
if problem.stat.frontend_question_id == frontend_question_id {
2424

2525
if problem.paid_only {
2626
return None
@@ -38,6 +38,7 @@ pub fn get_problem(id: u32) -> Option<Problem> {
3838
content: resp.data.question.content,
3939
sample_test_case: resp.data.question.sample_test_case,
4040
difficulty: problem.difficulty.to_string(),
41+
question_id: problem.stat.question_id,
4142
})
4243
}
4344
}
@@ -58,6 +59,7 @@ pub struct Problem {
5859
#[serde(rename = "sampleTestCase")]
5960
pub sample_test_case: String,
6061
pub difficulty: String,
62+
pub question_id: u32,
6163
}
6264

6365
#[derive(Serialize, Deserialize)]

0 commit comments

Comments
 (0)