Add unfinished path command

This commit is contained in:
Joscha 2022-10-22 01:02:33 +02:00
parent 345462915b
commit 853e09517f
3 changed files with 38 additions and 0 deletions

View file

@ -1,5 +1,7 @@
mod ingest;
mod path;
mod reexport;
pub use ingest::ingest;
pub use path::path;
pub use reexport::reexport;

View file

@ -0,0 +1,33 @@
use std::fs::File;
use std::io::{self, BufReader};
use std::path::Path;
use crate::data::AdjacencyList;
use crate::util;
pub fn path(datafile: &Path, from: &str, to: &str) -> io::Result<()> {
eprintln!(">> Import");
let mut databuf = BufReader::new(File::open(datafile)?);
let mut data = AdjacencyList::read(&mut databuf)?.change_page_data(f32::INFINITY);
eprintln!(">> Locate from and to");
let from = util::normalize_link(from);
let to = util::normalize_link(to);
let (from_i, from_p) = data
.pages
.iter()
.enumerate()
.filter(|(_, p)| !p.redirect)
.find(|(_, p)| util::normalize_link(&p.title) == from)
.unwrap_or_else(|| panic!("no article called {from}"));
let (to_i, to_p) = data
.pages
.iter()
.enumerate()
.filter(|(_, p)| !p.redirect)
.find(|(_, p)| util::normalize_link(&p.title) == to)
.unwrap_or_else(|| panic!("no article called {to}"));
dbg!(from_i, from_p, to_i, to_p);
Ok(())
}

View file

@ -13,6 +13,8 @@ enum Command {
Ingest,
/// Read and reexport brood data.
Reexport { to: PathBuf },
/// Find a path from one article to another.
Path { from: String, to: String },
}
#[derive(Debug, Parser)]
@ -27,5 +29,6 @@ fn main() -> io::Result<()> {
match args.command {
Command::Ingest => commands::ingest(&args.datafile),
Command::Reexport { to } => commands::reexport(&args.datafile, &to),
Command::Path { from, to } => commands::path(&args.datafile, &from, &to),
}
}