begin working on scraping
This commit is contained in:
parent
11caaf9c24
commit
9709d929ea
1 changed files with 30 additions and 1 deletions
31
src/main.rs
31
src/main.rs
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{fs::{self, DirEntry}, path::Path, env};
|
use std::{env, fmt::Debug, fs::{self, DirEntry}, path::Path};
|
||||||
use bencode::{decode, Value};
|
use bencode::{decode, Value};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
@ -11,6 +11,11 @@ enum Command {
|
||||||
Index {
|
Index {
|
||||||
#[arg(short='p', long, default_value="torman.db", help="path to transmission dir with \"torrents\" and \"resume\" dirs")]
|
#[arg(short='p', long, default_value="torman.db", help="path to transmission dir with \"torrents\" and \"resume\" dirs")]
|
||||||
path: String
|
path: String
|
||||||
|
},
|
||||||
|
|
||||||
|
Scrape {
|
||||||
|
#[arg(short='f', long, help="filter torrents by their destination field")]
|
||||||
|
destination: String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,6 +210,27 @@ fn index(db: Connection, path: &String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct FilteredTorrent {
|
||||||
|
pub id: i64,
|
||||||
|
pub publisher_url: String
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scrape(db: Connection, destination: &String) {
|
||||||
|
let mut stmt = db.prepare("SELECT id,publisher_url FROM torrent WHERE destination = ?1;").unwrap();
|
||||||
|
let torrents = stmt.query_map([destination], |row| {
|
||||||
|
Ok(FilteredTorrent {
|
||||||
|
id: row.get(0)?,
|
||||||
|
publisher_url: row.get(1)?
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.expect("query_map")
|
||||||
|
.filter_map(|f| f.ok());
|
||||||
|
|
||||||
|
for torrent in torrents {
|
||||||
|
dbg!(torrent.id, torrent.publisher_url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
@ -213,6 +239,9 @@ fn main() {
|
||||||
match &args.command {
|
match &args.command {
|
||||||
Command::Index { path } => {
|
Command::Index { path } => {
|
||||||
index(db, path);
|
index(db, path);
|
||||||
|
},
|
||||||
|
Command::Scrape { destination } => {
|
||||||
|
scrape(db, destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue