From b8fdd19c2a431935d1d3eb73684d30449d171429 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Wed, 19 Jun 2024 02:54:59 +0300 Subject: [PATCH] done with scraping --- src/main.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main.rs b/src/main.rs index 11d3e8c..f3bf8d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -250,6 +250,33 @@ fn scrape(db: Connection, destination: &String) { .unwrap() .as_str() ).unwrap(); + + let category_id = { + let result = db.query_row( + "SELECT id FROM category WHERE forum_id = ?1", (forum_id,), + |row| Ok(row.get::(0)?) + ); + + match result { + Ok(id) => id, + Err(_) => { + db.query_row("INSERT INTO category (forum_id) VALUES (?) RETURNING id;", + (forum_id,), + |row| Ok(row.get::(0)?) + ).unwrap() + } + } + }; + + let result = db.execute( + "INSERT INTO torrent_category (torrent_id,category_id) VALUES (?,?);", + (torrent.id, category_id) + ); + + match result { + Ok(_) => println!("torrent {} category_id {} forum_id {}", torrent.id, category_id, forum_id), + Err(e) => eprintln!("torrent {} torrent_category error: {:#?}", torrent.id, e) + } } }